What code should be inserted?

Given:
<code>
public class Bark {
// Insert code here – Line 5
public abstract void bark(); // Line 6
} // Line 7
// Line 8
// Insert code here – Line 9
public void bark() {
System.out.println(“woof”);
}
}
</code>
What code should be inserted?

Given:

public class Bark {
// Insert code here - Line 5
public abstract void bark(); // Line 6
} // Line 7
// Line 8
// Insert code here - Line 9
public void bark() {
System.out.println("woof");
}
}

What code should be inserted?

A.
5.class Dog {
9. public class Poodle extends Dog {

B.
5. abstract Dog {
9. public class poodle extends Dog {

C.
5. abstract class Dog {
9. public class Poodle extends Dog {

D.
5. abstract Dog {
9. public class Poodle implements Dog {

E.
5. abstract Dog {
9. public class Poodle implements Dog {

F.
5. abstract class Dog {
9. public class Poodle implements Dog {

Explanation:

Dog should be an abstract class. The correct syntax for this is: abstract class Dog {
Poodle should extend Dog (not implement).



Leave a Reply 2

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


noir

noir

Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user.

Abstract classes may or may not contain abstract methods ie., methods with out body ( public void get(); )

But, if a class have at least one abstract method, then the class must be declared abstract.

Declaring a method as abstract has two consequences:

The class containing it must be declared as abstract.

Any class inheriting the current class must either override the abstract method or declare itself as abstract.