Question: Are the given code correct using superclass and subclass concepts in Java? I have some notes about the code but didn't understand if it's correct

Are the given code correct using superclass and subclass concepts in Java?

I have some notes about the code but didn't understand if it's correct or not.

Code #1 : I

t says Correct and ther's invisible call to superclass constructor

public class Shape {

public Shape () { } // Constructor implementation for Shape class

public Shape (String color, boolean filled) {

.. // Constructor implementation for Shape class with parameters

} }

public class Circle extends Shape{

public Circle(double radius) {

// Call the superclass constructor with no arguments

this.radius = radius;} //Set the radius for the Circle

}

Code # 2 :

It says incorrect and no such call exists, Java will automatically make a call to super() at the beginning of the constructor, if there exist an empty constructor.

public class Shape {

public Shape (String color, boolean

filled) {..}

}

public class Circle extends Shape{

public Circle() { }

}

Code #3:

It says correct and Java will automatically make a call to default super() at the beginning of the constructor, as no constructors in the parent class.

public class Shape {

}

public class Circle extends Shape{

public Circle() { }

}

Code #4:

It says Correct and Java will automatically make a call to super() at the beginning of the constructor, if there exist an empty constructor.

public class Shape {

public Shape () { }

public Shape (String color, boolean

filled) {..}

}

public class Circle extends Shape{

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!