Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

5. Provide opportunities for retesting when the stakes are high.

Answered: 1 week ago

Question

Draw a picture consisting parts of monocot leaf

Answered: 1 week ago