CLASS - defines shape and nature of objects also a new data type. Once this data type is created then a object of this type can be created.a class contain data called instance variable and code that operates that data called method.
Object :- a object contains all copy of instance variable .
e.g- class Box{
double width;
double height;
}
Box b =new Box(); // b is a reference variable to object of Box class and it has type of class Box.
// b stores the address of object of class Box.
USE OF DOT OPERATOR?
to access the copy of variable among each object . here b reference variable has copy of double width and double height so to access them we use dot operator .Here comes a e.g of code reusability.
CONSTRUCTOR :-
1. objects are allowed to get initialize whenever they are created using constructor.
2.it is called before the "new".
3. constructor does not have return type because it is already of class type .
use of THIS:-
1. it refers to current object.
2. it is illegal to create two local variable of same name ;but it can be done using this keyword.
3.we can have local variable which overlap with name of instance variable,
e.g:-
class Box{
double width;
double height;
Box (double width,double height)
{
this.width=width;// width on left side refer to instance variable
this.height= height;// height on left side refer to instance variable.
}
Call By Value:- whenever we pass primitive data type as parameter it is passed as call by value.
here change in value of argument does not impact on the subroutine variables.
Call By reference :- the object are always passed as call by reference because the reference variable carry nothing but the reference of object or its address we can say so any change in the passed object will make impact on original object.
MORE TO COME..
Object :- a object contains all copy of instance variable .
e.g- class Box{
double width;
double height;
}
Box b =new Box(); // b is a reference variable to object of Box class and it has type of class Box.
// b stores the address of object of class Box.
USE OF DOT OPERATOR?
to access the copy of variable among each object . here b reference variable has copy of double width and double height so to access them we use dot operator .Here comes a e.g of code reusability.
CONSTRUCTOR :-
1. objects are allowed to get initialize whenever they are created using constructor.
2.it is called before the "new".
3. constructor does not have return type because it is already of class type .
use of THIS:-
1. it refers to current object.
2. it is illegal to create two local variable of same name ;but it can be done using this keyword.
3.we can have local variable which overlap with name of instance variable,
e.g:-
class Box{
double width;
double height;
Box (double width,double height)
{
this.width=width;// width on left side refer to instance variable
this.height= height;// height on left side refer to instance variable.
}
Call By Value:- whenever we pass primitive data type as parameter it is passed as call by value.
here change in value of argument does not impact on the subroutine variables.
Call By reference :- the object are always passed as call by reference because the reference variable carry nothing but the reference of object or its address we can say so any change in the passed object will make impact on original object.
MORE TO COME..
Thanks
ReplyDelete