public class Hello { public Hello() { System.out.println("a"); } public void test(){} public static void main(String arg[]) { Hello h = new Hello(); Hello h=new sub();// this is not compiling
} class sub extends Hello { Hello h=new sub(); public sub() { super(); System.out.println("s");
}
} }
Query:- Why we can't do "Hello h=new sub();" in the main method in this class?
Did you read the error message ? I think it's very clear about what the problem is. If you don't understand the error message, post it here and someone will explain. [ March 27, 2008: Message edited by: Joanne Neal ]
if you don't need to make inner class, just try bring 'sub' class our of Hello and try it. like this:
public class Hello { public Hello() { System.out.println("a"); } public void test(){} public static void main(String arg[]) { Hello h = new Hello(); Hello h=new sub();// this is not compiling
} }
class sub extends Hello { Hello h=new sub(); public sub() { super(); System.out.println("s");