Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following abstract Dance class. abstract class Dance {private Strin

ID: 3820608 • Letter: C

Question

Consider the following abstract Dance class. abstract class Dance {private String music public Dance (String m) {music = m;} public String getMusic () {return music;} public abstract void playMusic(); public abstract void danceBasic ();} Which the following classes correctly declares a subclass of Dance? Subclass-1 class Tango extends Dance {public Tango (String m) {super (m);} public void playMusic () {System. out. println ("Play" + getMusic();} public void danceBasic () {System. out. println ("Dance fwd, fwd, fwd-side-drag");}} Subclass-2 class Tango extends Dance {public Tango() {} public void playMusic() {System. out. println ("Play music");} {System. out. println ("Dance fwd, fwd, fwd-side-drag");}} Subclass-3 class Tango extends Dance {public void playMusic () {System. out. println ("Play music");} public void danceBasic () {System. out. println ("Dance fwd, fwd, fwd-side-drag");} public void makeRoutine () {System. out. println ("Make dance routine");}} (A) Subclass-1 only (B) Subclass-2 only (C) Subclass-3 only (D) Subclass-2 and Subclass-3 only (E) Subclass-1, Subclass-2 and Subclass-3

Explanation / Answer

Answer: (A) Subclass -1 only

Explanation: An abstract class is a class which is declared as abstract, it may or may not contain abstract methods. If it contains any abstract methods, the subclass that is extended from the abstract class must implement all the abstract methods of the abstract class.

Moreover, an abstract class cannot be instatiated, it is instantiated with the help of subclasses hence abstract classes can have constructors.

In the above abstract class Dance we have a parameterized contructor, a get method and two abstract methods.

The subclass of the Dance class must impleted both the abstract methods and also should implicitly call the super class constructor.

If the consider the given subclass,

Subclass-1 has a constructor that implicitly calls the super class constructor

public Tango (String m) { super(m); } //constructor that calls super class contructor

It has has implementation for both the abstract methods.

public void playMusic() { System.out.println("Play "+getMusic());}
public void danceBasic() { System.out.println("Dance fwd, fwd, fwd-side-drag"); }

Hence Subclass1 is a correctly declared subclass of Dance

Now lets see Subclass -2

In Subclass-2 we have both the abstract methods implemented

public void playMusic() { System.out.println("Play "+getMusic());}
public void danceBasic() { System.out.println("Dance fwd, fwd, fwd-side-drag"); }

But if you observe the constructor, it does not contain any implicit call of the super class constructor, hence this is invalid.

Now, lets see Subclass-3

In Subclass-2 we have both the abstract methods implemented

public void playMusic() { System.out.println("Play "+getMusic());}
public void danceBasic() { System.out.println("Dance fwd, fwd, fwd-side-drag"); }

But if you observe we don't have a constructor here, though a default constructor is created while compiling it is still invalid as it does not contain any implicit call of the super class constructor, hence this is also invalid.

Hence only Subclass-1 is a valid subclass declaration.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote