Documente Academic
Documente Profesional
Documente Cultură
Bajaj-Pulsor
Bike
Suzuki-MAX
Objects
(actual and physical entity)
Data Member and Method Members
A class is composed by a set of Attributes
(Properties) and Behavior.
Properties are represented by Data Members and
Behavior is simulated by Method Members.
Data
Student Members X Y
Name Name: Amit Name: Rahul
RollNo RollNo: 9 RollNo: 10
FName FName: Mohan FName: Sohan
DOB DOB:01/01/80 DOB: 02/02/81
getAdmission() getAdmission() getAdmission()
getTransfer() getTransfer() getTransfer()
feeDeposite() feeDeposite() feeDeposite()
showDetails() showDetails() showDetails()
Method
Class Members Object 1 Object 2
How to declare a Class in Java
Z is shared
public class test by A,B and C
{ int x; Test z objects
int y;
static int z;
……………… X X X
} y y y
A B C
How to create Objects
A class itself does not occupy any space, it defines a blue-print
for the objects only. When object is instantiated then it
occupies space in the memory. An object is created by the
following steps-
Declaration:
Object is declared like an ordinary variables using class name
as data type.
Instantiation:
An object is instantiated by using new keyword.
Initialization:
The new operator followed by a call to the constructor
method ( method having same name as class) is used to
initialize and object.
student x; // x object is declared
x= new student(); // x is instantiated and initialized.
Student x = new student(); // all in a single step (alternate)
Creating Objects- An Example
// define a class
public class city
{ String name;
long population;
void display()
{ System.out.println(“City Name: ”+name);
System.out.println(“Population: ”+population);
}
}
Automobile Human
Vehicle Transport
Teacher Student
X A B C
X A B Z
Y P
Y Z Z X Y X Y