Doubt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Doubt

Can anyone say wt is wrong in execution https://code.sololearn.com/cu5suyLW71zi/?ref=app

18th Jul 2020, 8:33 AM
Haritha Vuppula
Haritha Vuppula - avatar
1 Answer
+ 5
Haritha Vuppula index is not a static variable so you can't access directly with class. Call by object myApp. And in constructor you need to write. this.index = index; If you will not do output will be 1 ----------------------------- class Super1 { public int index = 1; } class App extends Super1{ public App(int index) { this.index = index; } public static void main(String args[]) { App myApp = new App(10); System.out.println(myApp.index); } }
18th Jul 2020, 8:35 AM
A͢J
A͢J - avatar