Reputation: 1052
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
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
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
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