Java Inheritance, Interfaces, Generics, and Static Methods

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

23 Terms

1
New cards

What is an abstract class?

A class that cannot be instantiated; may contain abstract (no body) and concrete methods.

2
New cards

Can abstract classes have constructors?

Yes, subclasses can call them with super().

3
New cards

What keyword is used for inheritance?

extends

4
New cards

What is polymorphism?

When a superclass reference points to a subclass object, and the actual method called depends on the object type.

5
New cards

Can a class extend multiple classes?

No, Java supports only single inheritance.

6
New cards

What keyword is used to implement an interface?

implements

7
New cards

What can an interface contain?

Abstract methods (by default), default/static methods, and public static final constants.

8
New cards

Can a class implement multiple interfaces?

Yes, multiple interfaces are allowed.

9
New cards

Why can't you use ArrayList?

Generics work only with objects, not primitives.

10
New cards

What is the workaround for ArrayList?

Use the wrapper class: ArrayList.

11
New cards

What is autoboxing?

Automatic conversion from primitive → wrapper (int → Integer).

12
New cards

What is unboxing?

Automatic conversion from wrapper → primitive (Integer → int).

13
New cards

What is the wrapper class for double?

Double

14
New cards

Comparable vs Comparator — key difference?

Comparable = natural order (inside class, compareTo). Comparator = flexible order (outside class, compare).

15
New cards

Can you have multiple Comparators for a class?

Yes, you can define as many as needed.

16
New cards

Can you have multiple Comparables for a class?

No, only one natural order.

17
New cards

What does static mean for a variable?

Shared by all objects; class-level.

18
New cards

What does static mean for a method?

Belongs to the class; can be called without creating an object.

19
New cards

Can a static method access instance variables directly?

No, because it has no this (no object context).

20
New cards

Why is main static?

So the JVM can call it without creating an object first.

21
New cards

Dynamic Binding or Late Binding is

Because of overridden method and the use of the appropriate method during execution

22
New cards

What is an interface

A collection of abstract methods and constants

23
New cards

What is Polymorphism in Java?

dThe feature of deciding which overridden method will be used at the run time of a program