Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
16 Cards in this Set
- Front
- Back
The Java programming language allows you to define a class within another class. Such a class is called a .......... class
|
Nested Class
|
|
Nested classes are divided into two categories...
|
static and non-static
|
|
Nested classes that are declared static are called.......... Non-static nested classes are called ..........
|
static nested classes, inner classes
|
|
.......... have access to other members of the enclosing class, even if they are declared private.
|
Non-static nested classes (inner classes),
|
|
.......... do not have access to other members of the enclosing class.
|
Static nested classes
|
|
Why Use Nested Classes?
3 reasons |
1. It is a way of logically grouping classes that are only used in one place. e.g. Helper Classes.
2.It increases encapsulation 3. It can lead to more readable and maintainable code |
|
Like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class: it can use them only through an ..........
|
object reference.
|
|
Static nested classes are accessed using the enclosing class name:
|
e.g.
OuterClass.StaticNestedClass |
|
What is the syntax to create an object for the static nested class?
|
OuterClass.StaticNestedClass nestedObjectname = new OuterClass.StaticNestedClass();
|
|
Objects that are instances of an inner class exist within an instance of the outer class. Consider the following classes:
|
class OuterClass {
... class InnerClass { ... } } |
|
An instance of InnerClass can exist only within an instance of .......... and has direct access to the methods and fields of its enclosing instance.
|
OuterClass
|
|
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
|
OuterClass.InnerClass innerObject = outerObject.new InnerClass();
|
|
There are two additional types of inner classes. These are .......... and .......... classes.
|
Local and Anonymous Classes.
|
|
Local Classes are declared where?
|
You can declare an inner class within the body of a method.
|
|
An anonymous class is the same as a local class except it is ..........
|
without a name.
|
|
What modifiers can you apply to an inner class?
|
You can use the same modifiers for inner classes that you use for other members of the outer class.
|