public class inheritex { int i=5; } class inheritex1 extends inheritex { int i=3; static void main(String args[]) { inheritex1 ex=new inheritex1(); System.out.println(ex.i); } }
Here i am getting the error, class inheritex is public and should be declared in a file named inheritex.java what's wrong in this? please explain me this....
Thanks Preparing scjp5
Preethi Dev
Ranch Hand
Joined: Sep 07, 2008
Posts: 265
posted
0
sorry here is the correct code!
public class inheritex { int i=5; } class inheritex1 extends inheritex { int i=3; public static void main(String args[]) { inheritex1 ex=new inheritex1(); System.out.println(ex.i); } }
Here i am getting the error, class inheritex is public and should be declared in a file name inheritex.java what's wrong in this? please explain me this....
If a class x is declared public it should be saved in the file x.java.otherwise the compiler complains.This restriction is not enforced if both the classes have default access.