> class members java ~ Online tutorial

class members java

Class Members
I wouldn’t want to belong to any club that would accept me as a member.
The members of a class type are all of the following:
• Members inherited from its direct superclass (§8.1.4), except in class Object,
which has no direct superclass
• Members inherited from any direct superinterfaces (§8.1.5)
• Members declared in the body of the class (§8.1.6)
Members of a class that are declared private are not inherited by subclasses
of that <a href="http://gan.doubleclick.net/gan_click?lid=41000000035692251&pubid=21000000000397534">class</a>. Only members of a class that are declared protected or public are
inherited by subclasses declared in a package other than the one in which the class
is declared.
We use the phrase the type of a member to denote:
• For a field, its type.
• For a method, an ordered 3-tuple consisting of:
argument types: a list of the types of the arguments to the method member.
return type: the return type of the method member and the
throws clause: exception types declared in the throws clause of the method
member.
Constructors, static initializers, and instance initializers are not members and
therefore are not inherited.
The example:
class Point {
int x, y;
private Point()
{
reset();
}
Point(int x, int y)
{
this.x = x; this.y = y;
}
private void reset()
{
this.x = 0;
this.y = 0; }
}
class ColoredPoint extends Point
{
int color;
void clear() { reset(); } // error
}
class Test
{
public static void main(String[] args)
{
ColoredPoint c = new ColoredPoint(0, 0);// error
c.reset(); // error
}
}
causes four compile-time errors:
• An error occurs because ColoredPoint has no constructor declared with two
integer parameters, as requested by the use in main. This illustrates the fact
that ColoredPoint does not inherit the constructors of its superclass Point.
• Another <a href="http://gan.doubleclick.net/gan_click?lid=41000000035692251&pubid=21000000000397534">Error</a> occurs because ColoredPoint declares no constructors, and
therefore a default constructor for it is automatically created  and this
default constructor is equivalent to:
ColoredPoint()
 {
super();
 }
which invokes the constructor, with no arguments, for the direct superclass of
the class ColoredPoint. The error is that the constructor for Point that takes
no arguments is private, and therefore is not accessible outside the class
Point, even through a superclass constructor invocation 

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: