Académique Documents
Professionnel Documents
Culture Documents
Chakradhar
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
implements
extends
SUPER 1 SUPER 2
SUB
SUB
extends 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;
}
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
{}
Extends
• In interfaces extends is used to extend one
or more interfaces into another interface.
interface A interface B
{ {
} }
interface NewInt extends A
{}
class NewInt extends A, B
{}
Polymorphism
• Many ways of outputs for single type
of request.
Ex: Math.sqrt(5);
static
• Static Block is used to initialise the static
variables and this block will be executed
for only once i.e. at the time of loading a
class.
Example:
static int a;
static
{
a=5;
}
Static (5.0)
• Static Import is used to qualify the access to
static members without inheriting from the
class or interface.
• The program imports either all members or
individual member of a class or interface.
Example:
import static java.lang.Math.PI;
double a=PI*r*r;
import static java.lang.Math.*;
double d=sqrt(9);
double d=tan(30);
final
• final keyword is used declare constants
which can not change its value of
definition.
Private OK NO NO NO NO
Default OK OK Instance NO NO
Protect OK OK Instance OK NO
import package.classes;
Packages
• Compiling a programme with package
javac –d <path> FileName.java
javac –d <path> –classpath <path> File.java