0
Constructor Chaining in Java Please help what is wrong in this code as it does not compile and throws exception at this(hello())
public class Program extends Parent { public static void main(String[] args) { Program p=new Program (); } } class Parent{ Parent(String s){ } Parent (){ this(hello()); } static void hello(){ System.out.println("Heee"); }
2 Answers
+ 1
Marked static because you cannot invoke an instance (in other words, nonstatic) method (or access an instance variable) until after the super constructor has run.