0
Why the constructor does not change class property? Or is there another reason?
class Practical{ int count; public void Practical(){ count = 7; } public static void main(String[] args) { Practical p = new Practical(); System.out.println(p.count); } }
1 Answer
+ 2
You declared the constuctor wrong. You declared it like a method. Remove âvoidâ and it will work.
public Practical() {
count = 7
}