Escolar Documentos
Profissional Documentos
Cultura Documentos
Joshi
INHERITANCE
INHERITANCE
• Acquiring the properties of an existing Object
into newly creating Object to overcome the
redeclaration of properties in deferent
classes.
• These are 3 types:
1.Simple Inheritance
SUPER SUPER
extends extends
SUB
implements
extends
• syntax:
abstract returntype methodName(arguments);
ABSTACT CLASS
• A class with at least one abstract
method.
• Explicitly creating an instance on
abstract class is not possible as it is an
incomplete class, but implicitly it
creates an instance when we try to
create an instance of its sub class.
• Abstract methods has to be overridden
by extending the abstract class.
ABSTRACT CLASS
abstract class Calculator
{
int sum(int a, int b)
{
return a+b;
}
abstract double squareRoot(double d);
}
INTERFACE
INTERFACE
• A class with all abstract methods.
• Instance will not be created for interface
either explicitly or implicitly.
• All the properties of interface are static
and final.
• We can implement any number of
interfaces into single class.
• Used in Dynamic Polymorphism
syntax of Interface
interface <interface_name>
{
static final variables;
abstract methods declaration();
}
implements
• Is a keyword used to implement one or more
interfaces into a class.
interface A interface B
{ {
} }
class NewClass implements A, B
{}
class NewClass extends One implements A, B
{}
Polymorphism
• Many ways of outputs for single type
of request.
Ex: Math.sqrt(5);
final
• final keyword is used declare constants
which can not change its value of
definition.
• final Variables can not change its
value.
• final Methods can not be Overridden
or Over Loaded
• final Classes can not be extended or
inherited
Access Specifiers
Access Specifiers
Same Pack Same Pack Diff Pack
In Diff Pack
Sub Diff Sub
Class Diff Class
Class Class Class
Private OK NO NO NO NO
Default OK OK Instance NO NO
Protect OK OK Instance OK NO
import package.classes;