Professional Documents
Culture Documents
Week 5 - Objects and Classes
Week 5 - Objects and Classes
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.
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’.