+ 2
Can we use constructors from parent class for subclass?
Hey guys! I have a question and the question is that can be get access of constructors from parent class for subclass. Please reply me
2 Réponses
+ 12
Here is best explanation
https://code.sololearn.com/cJI0TrD1mipb/?ref=app
+ 1
If class A extends class B, you can call the constructor of the parent class with the keyword "super"
----------------------------------------
class B {
B() { //constructor for a B object
System.out.print("B object created");
}
}
class A extends B {
A() { //constructor for an A object
super(); //calls the B constructor
}
}