Java Reference
In-Depth Information
18
.
A reference variable of a class can refer to either an object of its own class or
an object of its subclass.
19
.
In early binding, a method's definition is associated with its invocation
when the code is compiled.
20
.
In late binding, a method's definition is associated with its invocation at
execution time, that is, when the method is executed.
21
.
Except for a few (special) cases, Java uses late binding for all methods.
22
.
The term polymorphism means assigning multiple meanings to the same
method. In Java, polymorphism is implemented using late binding.
23
.
You cannot automatically consider a superclass object to be an object of a
subclass. In other words, you cannot automatically make a reference variable
of a subclass type point to an object of a superclass type.
24
.
Suppose that
supRef
is a reference variable of a superclass type. Moreover,
suppose that
supRef
points to an object of a subclass. You can use an
appropriate cast operator on
supRef
and make a reference variable of the
subclass point to the object. On the other hand, if
supRef
does not point to
a subclass object, and you use a cast operator on
supRef
to make a
reference variable of the subclass point to the object, then Java will throw
a
ClassCastException
—indicating that the class cast is not allowed.
25
.
An abstract method is a method that has only the heading, not the body.
Moreover, the heading of an abstract method is terminated with a semicolon.
26
.
An abstract class is a class that is declared with the reserved word
abstract
in its heading.
27
.
The following are some of the facts about abstract classes:
An abstract class can contain instance variables, constructors, a finalizer,
and nonabstract methods.
An abstract class can contain an abstract method(s).
If a class contains an abstract method, then the class must be declared abstract.
You cannot instantiate an object of an abstract class. You can only
declare a reference variable of an abstract class type.
You can instantiate an object of a subclass of an abstract class, but only if
the subclass gives the definitions of all the abstract methods of the
superclass.
28
.
An
interface
is a class that contains only abstract methods and/or named
constants.
29
.
Java allows a class to implement more than one interface. This is, in fact, the
way to implement a form of multiple inheritance in Java.
30
.
In composition, one or more members of a class are objects of one or more
other classes.
31
.
Composition (aggregation) can be viewed as a ''has-a'' relationship.
1
0
Search WWH ::
Custom Search