}
The static nested class can be instantiated as follows:
MyClass.Nested nested = new MyClass.Nested();
To instantiate a static nested class,
both the outer class name
and the nested class name need to be specified. In the above
code, the class name is MyClass and
the Static Nested class
name is Nested.
086.
087.
CHAPTER
08
Inheritance
Give an example of illegal method overriding.
Answer:
The following code is an example of illegal method overriding:
class Electronics {
public void displayPrice() {}
}
class Camera extends Electronics {
public void displayPrice() throws Exception {}
}
In this code snippet, the class Camera is a sub–class of the
Electronics class. The displayPrice() method is
overridden in the Camera class. However,
this code will cause a
compilation error. This is because the displayPrice() method
in Camera class specifies that it throws an Exception. One of the
rules of method overriding is that the
overridden method must not
throw a new or a broader checked exception.
Do'stlaringiz bilan baham: