Inner classes Flashcards

1
Q

What inner classes are there?

A

Inner class, local class, anonymous class, static nested class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are local classes?

A

Those are ones created inside a method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is relationship of local classes and upper class?

A

Inner class can read all instance variables and methods from upper class or method, regardless if they are final or effectively final. No initialization is needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are anonymous classes?

A

Implementation of a class or interface. They are implemented inline with a reference type. It is actually extending and implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are static nested classes?

A

Classes that are defined inside another class, and they are static.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is relationship of static nested classes and upper class?

A

Members of a static nested classes cannot use members of upper class, but upper class can use members from static nested class -> A.B.something()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are inner classes?

A

Inner class is a class defined inside another class - it is nested.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are characteristics of inner classes?

A

They can have all access modifiers, they can extend and implement. They can have static members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is relationship of inner classes and upper class?

A

Inner most class can access all members from its upper classes. It can access generics that are passed to upper class, but need to watch out for overshadowing (must use different letters for each class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we instantiate nested classes? Let’s say C is inside B, B is inside A.

A

Need to instantiate A -> A a = new A();
Need to instantiate B -> A.B b = a.new B();
Need to instantiate C -> A.B.C c = b.new C();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we access instance members of class A from its nested class C?

A

A.this.something()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can we access instance members of class B from its nested class C?

A

B.this.something()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly