0% found this document useful (0 votes)
31 views

University of Cambodia: Class and Object

Class is a blueprint or template that defines the attributes and behaviors of objects. An object is an individual instance of a class. Some key points: 1. A class defines common properties and methods for a group of objects. 2. Objects are created from classes using the "new" keyword. 3. Classes allow for code reusability through inheritance and polymorphism. Multiple objects can be created from the same class. 4. Classes in Java can contain fields, methods, constructors and blocks to define properties and behaviors for objects instantiated from the class.

Uploaded by

Phanith Chea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

University of Cambodia: Class and Object

Class is a blueprint or template that defines the attributes and behaviors of objects. An object is an individual instance of a class. Some key points: 1. A class defines common properties and methods for a group of objects. 2. Objects are created from classes using the "new" keyword. 3. Classes allow for code reusability through inheritance and polymorphism. Multiple objects can be created from the same class. 4. Classes in Java can contain fields, methods, constructors and blocks to define properties and behaviors for objects instantiated from the class.

Uploaded by

Phanith Chea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIVERSITY OF CAMBODIA

COURSE: ITE202K JAVA STANDARD EDITION(J2SE)


TOPIC : CLASS AND OBJECT
CLASS AND OBJECT
Lecturer : Nhanh Nhim
 NUON VATHANA
Group : 5
 CHEA PHANITH
Student : Nuon Vathana
Chea Phanith
I.INTRODUCTION
 Classes and objects are the two main aspects of object-oriented programming, OOP.
 Class is a blueprint or template from which individual objects are created.
 A class in Java can contain fields, methods, constructors, blocks, nested class and interface.
 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.
2.BENEFIT OF CLASS AND OBJECT

1. Re-usability
 It means reusing some facilities rather than building it again and again. This is done with the use of a class. We
can use it ‘n’ number of times as per our need.
2. Data Redundancy
 This is a condition created at the place of data storage where the same piece of data is held in two separate
places. So the data redundancy is one of the greatest advantages of Class and Object. If a user wants a similar
functionality in multiple classes he/she can go ahead by writing common class definitions for the similar
functionalities and inherit them.
3. Code Maintenance
 This feature is more of a necessity for any programming languages, it helps users from doing re-work in many
ways. It is always easy and time-saving to maintain and modify the existing codes with incorporating new
changes into it.
3.SCOPE OF STUDY

Create a Class

Create an Object

Multiple Class and Object

Class Attributes
CREATE A CLASS

To create a class, use the keyword class:


CREATE AN OBJECT

In Java, an object is created from a class. We have already created the class named MyClass, so now we can use this
to create objects.
To create an object of MyClass, specify the class name, followed by the object name, and use the keyword new:
MULTIPLE OBJECT

You can create multiple objects of one class:


MULTIPLE CLASS

You can also create an object of a class and access it in another


class. This is often used for better organization of classes (one
class has all the attributes and methods, while the other class
holds the main() method (code to be executed)).
Remember that the name of the java file should match the class
name. In this example, we have created two files in the same
directory/folder:
• Main.java
• Second.java
4.PROCESSING

SHOW PROGRAM OUTPUT OR FIGURE


5.QUESTION

What is class and object

What is the benefit of a class and object

What is the relationship between class and object


6.SUMMARY

Class:
Product
-ID
-Name
-Price

ABC Anchor
-ID Coca -ID
-Name -ID -Name
-Price -Name -Price
-Price
REFERENCE:

 https://www.w3schools.com/java/java_oop.asp
 https://www.w3schools.com/java/java_classes.asp
 https://www.w3schools.com/java/java_class_attributes.asp
THANK YOU
FOR YOUR
ATTENTION

You might also like