CLASSES
Method Modifiers
8.4.3
An instance method that is not
abstract
can be overridden by an
abstract
method. For example, we can declare an
abstract
class
Point
that requires its
subclasses to implement
toString
if they are to be complete, instantiable classes:
abstract class Point {
int x, y;
public abstract String toString();
}
This
abstract
declaration of
toString
overrides the non
abstract toString
method of class
Object
( 20.1.2). (Class
Object
is the implicit direct superclass
of class
Point
.) Adding the code:
class ColoredPoint extends Point {
int color;
public String toString() {
return super.toString() + ": color " + color; //
error
}
}
results in a compile time error because the invocation
super.toString()
refers
to method
toString
in class
Point
, which is
abstract
and therefore cannot be
invoked. Method
toString
of class
Object
can be made available to class
ColoredPoint
only if class
Point
explicitly makes it available through some
other method, as in:
abstract class Point {
int x, y;
public abstract String toString();
protected String objString() { return super.toString(); }
}
class ColoredPoint extends Point {
int color;
public String toString() {
return objString() + ": color " + color;
//
correct
}
}
8.4.3.2
static
Methods
A method that is declared
static
is called a
class method
. A class method is
always invoked without reference to a particular object. An attempt to reference
the current object using the keyword
this
or the keyword
super
in the body of a
class method results in a compile time error. It is a compile time error for a
static
method to be declared
abstract
.
159
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved