Which two are true about the lines labeled A through D?

Given:

abstract class Boat {

String doFloat() { return “floating”; }

abstract void doDock();

}

class Sailboat extends Boat {

public static void main(String[] args) {

Boat b = new Sailboat(); // Line A

Boat b2 = new Boat(); // Line B

}

String doFloat() { return “slow float”; } // Line C

void doDock() { } // Line D

}

Which two are true about the lines labeled A through D?

Given:

abstract class Boat {

String doFloat() { return “floating”; }

abstract void doDock();

}

class Sailboat extends Boat {

public static void main(String[] args) {

Boat b = new Sailboat(); // Line A

Boat b2 = new Boat(); // Line B

}

String doFloat() { return “slow float”; } // Line C

void doDock() { } // Line D

}

Which two are true about the lines labeled A through D?

A.
The code compiles and runs as is.

B.
If only line A is removed, the code will compile and run.

C.
If only line B is removed, the code will compile and run.

D.
If only line D is removed, the code will compile and run.

E.
Line C is optional to allow the code to compile and run.

F.
Line C is mandatory to allow the code to compile andrun.

Explanation:
A: The code will compile. The abstract method doDock() is implemented fine, and doFloat() is overridden.
E: Line C overrides the implementation of doFloat(). This is optional.



Leave a Reply 13

Your email address will not be published. Required fields are marked *


Boris

Boris

Boat b2 = new Boat(); // Line B.. does not confuse anyone?

Martin

Martin

Chuck Norris can instantiate an abstract class.

Boris

Boris

cannot be instantiated. It contains abstract method: abstract void doDock();
The correct answers are B and E

Francesco

Francesco

Please do not confuse people …
Correct answers are C and E

ses

ses

Correct answers are C and E.

DONT confuse the people with your superficial knowledge

Robertinho

Robertinho

Correct answers are C and E.

Ray

Ray

Correct answers are C and E.

hieu

hieu

do not create instance Abstract class => C wrong!
mandatory Override abstract method inside class that extends from abstract class => F
😀 my email : [email protected]

DonDorian

DonDorian

C E

Please Compile
before reply!

Just poetry 😉

wolfatthegate

wolfatthegate

Amen