Colleagues, where I am stupid, help. Mistake.

class myOld{ public int oldN =1; } class myNew extends myOld{ super.oldN=2; } public class JavaApplication16 { public static void main(String[] args) { myNew i = new myNew(); System.out.println(i.oldN); } } 
  • class myNew extends myOld {myNew () {super.oldN = 2; }} if you want the variable to change when creating a class, then add a constructor. but in general, getters are setters, and also see the rules for naming (the class should not be a small letter, etc.) - Dmitry

1 answer 1

 class MyOld{ public int oldN =1; } class MyNew extends MyOld{ public MyNew(){ super.oldN=2; } }