Department of Computer Science and Engineering (CSE)
JAVA Programming (CST-254)
Objects & Classes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
Synonymous with data type
Object is like variable
data type is some Class
an instance of a Class
Classes contain:
implementation details
interface for programmers
Objects are complex variables
multiple pieces of internal data
carried out via methods
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
built in library of classes
String
Math
System
Arrays
Scanner
File
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
An object
data field 1
A Circle object
... State Data Field
radius = 5
data field n
method 1
Method
findArea
... Behavior
method n
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
Primitive type int i = 1 i 1
Object type Circle c c reference
c: Circle
Created using
new Circle() radius = 1
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
Primitive type assignment Object type assignment
i=j c1 = c2
Before: After: Before: After:
i 1 i 2 c1 c1
j 2 j 2 c2 c2
c1: Circle c2: Circle
radius = 5 radius = 9
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
Accessing Class Members
Objectname.variablename=value;
Objectname.methodname(parameter-list);
Declared using static modifier
Methods
declared inside the body
after declaring variables.
The general form of a method declaration is
Type methodname (parameter-list)
{
method-body;
}
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
The Keyword this
refer the current object.
invoke current class constructor.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Objects & Classes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
THANKS..
University Institute of Engineering (UIE)