7. MULTILEVEL
INHERITANCE
GRAND FATHER SUPER CLASS
FATHER INTERMEDIATE SUPERCLASS
CHILD SUB CLASS
8. A DERIVED CLASS WITH MULTILEVEL BASE CLASSES IS DECLARED AS
FOLLOWS
CLASS A
{
…………
…………
}
CLASS B extends A // first level
{
………….
………….
}
CLASS C //second level
{
………….
………….
}
13. OVERRIDING CAN BE DONE BY
DEFINING A METHOD IN THE SUB
CLASS THAT HAS THE SAME
NAME,SAME ARGUMENTS AND
SAME RETURN TYPE AS A
METHOD IN THE SUPER CLASS.
THIS IS KNOWN AS OVERRIDING.
14. FINALIZER METHODS
FINILIZATION IS JUST OPPOSITE TO
INITIALASATION.
JAVA RUN-TIME IS AN AUTOMATIC
GARBAGE COLLECTING SYSTEM.
IT FREES THE MEMORY RESOURCES USED
BY OBJECTS.
BUT OBJECTS MAY HOLD OTHER NON-
OBJECT RESOURCES SUCH AS FILE
DESCRIPTORS OR WINDOW SYSTEM
FONTS.
15. THE GARBAGE COLLECTOR CANNOT FREE
THESE RESOURCES.
IN ORDER TO FREE THIS WE USE FINALIZER
METHOD.
THIS IS SIMILAR TO
DESTRUCTORS.
THE FINALIZER METHOD IS SIMPLY
FINALIZE()
16. ABSTRACT METHODS
FINALIZER
HELPS US NOT TO RE-
DEFINE THE METHOD IN SUB
CLASS.
BUT
TO DO THE OPPOSITE, i.e.
REDEFINE THE METHOD IN SUB
CLASS,WE USE THE MODIFIER
KEYWORD abstract IN THE
METHOD DEFINITION
18. VISIBILITY CONTROL
IT
IS ALSO KNOWN AS ACCESS
MODIFIERS.THIS PROVIDES THREE
TYPES OF MODIFIERS:
PUBLIC
PRIVATE
PROTECTED
19. By simply declaring the variable or
method as public it is visible to
entire class in which it is defined.
A variable or method which is
declared as public has the widest
possible visibility and
accessible everywhere.
20.
21. FRIENDLY ACCESS
• When no access modifier is specified,the
member defaults to a limited version of public
accessibility known as “friendly” level of
access.
• this makes fields visible only in the same
package,but not in other packages.
22. The visibility lies in between the public
access and friendly access.
The protected modifier makes the fields
visible not only to all classes and sub
classes in the same package but also to
sub classes in other packages.
23. PRIVATE ACCESS
They enjoy the highest degree of protection.
They are accessible only with their own class.
They cannot be accessed and inherited
by sub classes.
The method declared as private behaves like a
method declared as final.
It prevents the method from being sub classed.
24. A field can be declared with two key
words private and protected together like:
Private protected int codenumber;
the visibility level is between the
“protected” access and private access.
This makes the fields visible in all
subclasses regardless of what package
they are in
25. USE PUBLIC IF THE FIELD IS TO BE VISIBLE
EVERYWHERE.
USE PROTECTED IF THE FIELD IS TO BE
VISIBLE EVERYWHERE IN THE CURRENT
PACKAGE AND ALSO SUBCLASSES IN
OTHER PACKAGES.
USE “DEFAULT” IF THE FIELD IS TO BE
VISIBLE EVERYWHERE IN THE CURRENT
PACKAGE ONLY.
USE PRIVATE PROTECTED IF THE FIELD IS