Inner and Abstract Classes & Interfaces Flashcards
1
Q
Java Interface
A
- a blueprint of a class
- an abstract type that is used to specify behavior(s)/function(s) that all the classes must implement
- it has static constants and abstract methods (not method body)
2
Q
Why do we need a Java Interface?
A
to overcome the problem of multiple inheritances
3
Q
List interface
A
- provides a way to store the ordered collection
- it is a child interface of Collection
- it is an ordered collection of objects in which duplicate values can be stored
- since List preserves the insertion order, it allows positional access and insertion of elements
4
Q
Vector
A
xxx
5
Q
synchronized
A
xxx
6
Q
What’s wrong with the code below?
List < String > fields = new List < String >;
A
‘List’ is abstract; cannot be instantiated.
7
Q
Explain codes:
ISaveable werewolf = new Monster (“Werewolf”, 20, 40);
System.out.println (((Monster) werewolf).getStrenth());
A
xxx
8
Q
How to create an instance of an inner class?
A
OuterClass.InnerClass reference = outerObject.new InnerClassConstructor()
Gearbox mcLaren = new Gearbox(6); Gearbox.Gear first = mcLaren.new Gear(1, 12.3);
9
Q
Inner class
A
it refers to the class that is declared within class or interface
10
Q
Types of Inner Classes
A
- Nested/Normal/Regular Inner Class
- Method Local Inner Class
- Static Nested Class
- Anonymous Inner Class
11
Q
Nested/Normal/Regular Inner Class
A
- when we declare any named class directly inside a class without a static modifier