Sei sulla pagina 1di 2

Constructors are the special type of methods which has same name as the class name.

we can call the constructors only by creating an abject.


It is impossible to call the constructors by using reference variable.
For one object one construtor will be executed.
Constructors cannot be declared as static and final.
constructors can be declared as two types
:1.Default constructor
2.Programmer defined constructor
If the Programmer do not specify any constructor in a class then the Programmer
will write Default constructor at compile time implicity
Each and every java class must and should have a constructor
Programmer defined constructor can be declared as two types:
1.Zero argument constructor
2.Parameteried constructor
we should not specify a return type for a constructor
Any variable can be declard with in the code of the class is called as global
variable.
Any variable can be declared with in the method defination and method declaration
is called local variables.
Global variables can be specified with the Static or non static.
global variables will be intialized with Default values by the compiler time
this statement is used to call one constructor to another constructor present in
the same class.
it should be written first line of the constructor body.
this keyword is used to differentiate between local and global variables whenever
they have same names.
Relations are used to relate one class to another class.
Relations between classes are used acheive two goals
*Reduce the number of lines of codes
METHODS:
Developing multiple methods with in a same class and same name which may differ
in :

*NO of arguments

*code Reusability
Relations are two types :Has-A relation
Is-A relation
Has-A relation:
It is a type of relation where the objects are related to each other based on the
dependency of one object over the another object,
Relations are used to relate one class to another class
Relations are used to acheive two goals
reduce the no lines of codes
code reusability
two types of relations:
Has-A relation:it is a type of relation where the objects are related to each other
based on the dependency of one object to another object.
Two types:Aggregation:
it is a type of relation where existance of one object is not
strongly dependent upon another object
Aggregation is acheived by creating global static reference
variable that points to the another class.
composition:It is a type of relation where the existance of one object is strongly
dependent upon another object
composition is acheived by creating global static reference variables
that points to another class
Super Statement:
it creates the object of an super class or parent class around which child class
object is created
The super statement also called as the constructor of super class or parent class
from constructor of child classor sub class
with in the subclass constructor we cannot write multiple super statements.Because
it will create the object of super classes multiple times.
super statement should be written at the first line of the constructor body
super statement can be wriiten explicity by the programmer and implicity by the
compiler
subclass construtor calling super class and super class construcor calling object
class constructor is called constructor chaining.

METHOD overloading:
Developing multiple methods with in a same class with the same name which may
differ in
1.NO of arguments
2.datatype of an arguments
3.order of an arguments
is called method overloading
*Two overloaded methods can have different return types.
*can have different acccess specifiers
*can have different access modifiers.
ADVANTAGE:
To perform same task in a class using different arguments we did not need
to to remember multiple method names
DISADVANTAGE:
As a developer for every each and every single class we have to maintain
documentation which is time consuming process
b It takes lots of time for the developer to understand the behaviour of
every overloaded methods without any documentations.

Potrebbero piacerti anche