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"); }

23rd Aug 2020, 10:18 AM
anshu kulshrestha
anshu kulshrestha - avatar
1 ответ
+ 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.
23rd Aug 2020, 10:32 AM
anshu kulshrestha
anshu kulshrestha - avatar