Search Header Logo

Understanding Abstract Classes and Interfaces

Authored by Sangaji Baskoro

Information Technology (IT)

University

Understanding Abstract Classes and Interfaces
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In Java, which keyword is used to declare an abstract class?

`interface`

`abstract`

`virtual`

`extends`

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following statements correctly describes an abstract class?

An abstract class can be instantiated directly using the `new` keyword

An abstract class cannot contain any concrete (non-abstract) methods

An abstract class may contain both abstract and non-abstract methods

An abstract class must implement all methods of an interface it references

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a correct characteristic of an interface in Java?

An interface can have instance variables with any access modifier

All methods in an interface are implicitly `public` and `abstract` (prior to Java 8)

An interface can be instantiated directly

An interface can extend an abstract class

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In Java, a class that implements an interface must:

Declare itself as abstract

Provide implementations for all abstract methods of the interface, unless the class is abstract

Use the `extends` keyword instead of `implements`

Override only the methods it chooses to implement

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following correctly identifies a key difference between an abstract class and an interface in Java?

An abstract class supports multiple inheritance, while an interface does not

An interface can have constructors, while an abstract class cannot

A class can implement multiple interfaces but can only extend one abstract class

An abstract class cannot have any implemented methods, while an interface can

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a valid use case for an abstract class?

When you want to define a contract that unrelated classes can implement

When you want to share common code and state among closely related classes

When you need a class to support multiple inheritance

When you want to define only method signatures without any implementation

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following Java code: ```java interface Drawable { void draw(); } class Circle implements Drawable { public void draw() { System.out.println("Drawing Circle"); } } ``` What will happen if the `draw()` method is removed from the `Circle` class?

The code will compile and run without errors

A runtime exception will be thrown

A compile-time error will occur because `Circle` does not implement all methods of `Drawable`

The `Circle` class will automatically inherit the `draw()` method from `Drawable`

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?