+ 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

17th Jun 2019, 4:29 AM
Anuj Raghu
Anuj Raghu - avatar
2 Respostas
17th Jun 2019, 5:05 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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 } }
17th Jun 2019, 4:53 AM
Alex Smith
Alex Smith - avatar