class? Super keyword calls the parent class constructor but does it also create an object? in other words, when using inheritance, is parent class object created?
for example, we have Parent.java .
public class Parent{
int age;
public Parent(int age){
this.age = age;
}
}
And Child.java
public class Child extends Parent{
public Child(int age){
super(age);
}
}
public class Main{
public static void main(String[] args) {
Child child = new Child();
}
}
Only child object created or both classes object created?
You can have it this way Parent newpr = new Child ();
What is your code trying to do?
I have showed my code sample and question is quite understandable I think.
Обсуждают сегодня