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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started