You are on page 1of 11

Class and

Objects
College of Computing and Information
Technologies
JAVA CLASSES
Everything in Java is associated with classes and
objects, along with its attributes and methods.
For example: in real life, a car is an object. The car has attributes, such as weight
and color, and methods, such as drive and brake.

A Class is like an object constructor, or a "blueprint"


for creating objects.
CREATE CLASSES
To create a class, use the keyword class:

defining fields
CREATE OBJECTS
In Java, an object is created from a class. To create
an object of Main, specify the class name, followed
by the object name, and use the keyword new:
CREATE OBJECTS
MULTIPLE
OBJECTS
MULTIPLE
CLASSES
You can also create an object of a class and access it
in another class. This is often used for better
organization of classes.
MULTIPLE
CLASSES
What is the output?
Create a class named 'Student' with String variable
'name' and integer variable stud_no'. Assign the
value of stud_no as '2' and that of name as "John"
by creating an object of the class Student.
ASSIGNMEN
T
Write a program that would print the information
(name, year of joining, salary, address) of three
employees by creating a class named 'Employee’.

The output should be as follows:


Name Year of joining Address
Robert 1994 64C- WallsStreat
Sam 2000 68D- WallsStreat
John 1999 26B- WallsStreat

You might also like