Srimanth
Srimanth

Reputation: 1052

No output In Eclipse for a simple java program

I think I have written this program pretty well. It gives me no errors, but it is not giving me any output either. What is wrong with this? I checked other programs to see if anything is wrong with Eclipse, but every other program is running except this.

Note: I am newbie Java learner. Explain the problem in detail. I know I have written the spelling of Inheritance wrong.

 public class Inheritence {
    int a;
    String b;

    Inheritence(int x, String y) {
        a = x;
        b = y;
    }
}

class B extends Inheritence {
    int c;

    B(int j, String k, int l) {
        super(4, "Srimanth");
        a = j;
        k = b;
        c = l;
    }

    public static void main(String args[]) {
        Inheritence obj1 = new Inheritence(4, "Srimanth");
        B obj2 = new B(4, "Srimanth", 5);

        System.out
                .println("The details of the guy are" + obj1.a + " " + obj1.b);
        System.out.println("The details of the guy are" + obj2.c);
    }

}

Upvotes: 0

Views: 436

Answers (3)

sujithvm
sujithvm

Reputation: 2411

The error in your code is that main method is defined in a non public class B . Move main method to public class Inheritence or define make class B subclass of Inheritence and Inheritence having main method.

Upvotes: 2

James
James

Reputation: 338

When I run it I get the following:

error: Class names, 'Inheritence', are only accepted if annotation processing is
explicitly requested
1 error

Try the changing the file name/class name.

Upvotes: 0

Arian Kiehr
Arian Kiehr

Reputation: 451

The name of the file is Inheritence.java?

In that case you should put different classes in different files, and call the one that have the main method (better write the parameters like "String[] args") probably can't find the main method

Upvotes: 0

Related Questions