SlideShare a Scribd company logo
Object-Oriented Programming with Java Oum Saokosal , Head of IT Department National Polytechnic Institute of Cambodia Tel: (855)-12-417214 E-mail: oum_saokosal@yahoo.com
Chapter 6 Objects and Classes (Revision) OOP Classes Objects Constructors Accessing Object’s Data and Methods
Object-Oriented Programming Why learning OOP? Java is a pure OOP OOP provides more flexibility, modularity, clarity, reusability Other Programming: C++, C#, VB .NET, ActionScript 3.0, Ruby etc. also use OOP. 3 concepts of OOP: Class Encapsulation Class Inheritance Polymorphism
Classes (1) What is a class? A class is similar to a template, blueprint or symbol (in Adobe Flash). A class creates many objects. Class Objects
Classes (2) In a class, there are : Data Fields (Properties) Behavior: Constructors Methods public class Student { private int id, String name; public Student(){} public Student (int inputID,  String inputName){ this.id = inputID; this.name = inputName; } public String toString(){ return id + name; } }
Constructors (1) What is constructor? A constructor is to construct (create) objects from a class. public class Student { private int id, String name; public Student(){} public Student (int inputID,String inputName){ this.id = inputID; this.name = inputName; } public String toString(){ return id + name; } }
Constructors (2) How to construct objects? Usually, we have many classes in a projects. So the student class will be created in other classes. To construct objects from student class: public class TestStudent { public static void main(String[] args){ Student stu; //To construct an object stu =  new Student(); System.out.println(stu.toString()); } }
Access Object’s Data and Methods To access method: public class TestStudent { public static void main(String[] args){ Student stu; //To construct an object stu = new Student(“123”,”Veasna”); System.out.println( stu.toString() ); } } To access data: Usually, We don’t access the data. If you like, you can do like :  stu.id = 123   in case  id  is  not private .
End of Revision

More Related Content

PPTX
Classes revision
PPT
Java sem i
PPTX
[OOP - Lec 06] Classes and Objects
PPT
9 cm604.14
PPTX
Classes revision
PPT
Classes and objects
PPTX
Introduction to OOP with java
Classes revision
Java sem i
[OOP - Lec 06] Classes and Objects
9 cm604.14
Classes revision
Classes and objects
Introduction to OOP with java

What's hot (20)

PPTX
Module 6 : Essentials of Object Oriented Programming
PPTX
C# Inheritance
PPTX
Encapsulation
PPTX
Oops concepts
PPT
Classes and objects
PPTX
Nested class
PPTX
Characteristics of oop
PPTX
Classes and Objects
PPTX
Object oriented programming concept- Saurabh Upadhyay
PPTX
Basic Concepts Of OOPS/OOPS in Java,C++
PPTX
CPP14 - Encapsulation
PPTX
Classes and objects
PPTX
Oo ps concepts in c++
PPTX
Basic concept of Object Oriented Programming
PPTX
Encapsulation
PPTX
Adbms 15 object data management group
PPTX
2CPP09 - Encapsulation
PPTX
Learn C# Programming - Encapsulation & Methods
PDF
Semantic Web - Ontology 101
PPTX
Inheritance in java
Module 6 : Essentials of Object Oriented Programming
C# Inheritance
Encapsulation
Oops concepts
Classes and objects
Nested class
Characteristics of oop
Classes and Objects
Object oriented programming concept- Saurabh Upadhyay
Basic Concepts Of OOPS/OOPS in Java,C++
CPP14 - Encapsulation
Classes and objects
Oo ps concepts in c++
Basic concept of Object Oriented Programming
Encapsulation
Adbms 15 object data management group
2CPP09 - Encapsulation
Learn C# Programming - Encapsulation & Methods
Semantic Web - Ontology 101
Inheritance in java
Ad

Viewers also liked (6)

PDF
Total oop in c# dot net
PPTX
Delegates in C#
PPTX
Fluent interface in c#
PPTX
interface in c#
PPTX
Delegates and events
PPTX
C# Delegates
Total oop in c# dot net
Delegates in C#
Fluent interface in c#
interface in c#
Delegates and events
C# Delegates
Ad

Similar to Chapter 6 OOP (Revision) (20)

PPT
Objected-Oriented Programming with Java
PPT
PDF
JAVA PPT -2 BY ADI.pdf
PPT
packages and interfaces
PPTX
Objects and Classes in JAVA introduction
PPTX
Ch-2ppt.pptx
PPT
OOP_1_TEG
PPT
Java lec class, objects and constructors
PPTX
Object Oriended Programming with Java
PDF
DOCX
javaopps concepts
PDF
ITFT-Classes and object in java
PPTX
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
PPTX
Classes, Inheritance ,Packages & Interfaces.pptx
PPT
Class and Object.ppt
PPTX
1707325642974_Classes fffand objects.pptx
PDF
Classes and objects
PPT
Lect 1-class and object
PPT
Core Java unit no. 1 object and class ppt
PPT
OOP concepts
Objected-Oriented Programming with Java
JAVA PPT -2 BY ADI.pdf
packages and interfaces
Objects and Classes in JAVA introduction
Ch-2ppt.pptx
OOP_1_TEG
Java lec class, objects and constructors
Object Oriended Programming with Java
javaopps concepts
ITFT-Classes and object in java
Chapter4.pptxdgdhgfshsfhtgjsjryjusryjryjursyj
Classes, Inheritance ,Packages & Interfaces.pptx
Class and Object.ppt
1707325642974_Classes fffand objects.pptx
Classes and objects
Lect 1-class and object
Core Java unit no. 1 object and class ppt
OOP concepts

More from OUM SAOKOSAL (20)

PPTX
Class Diagram | OOP and Design Patterns by Oum Saokosal
PPTX
Android app development - Java Programming for Android
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
PDF
Java OOP Programming language (Part 7) - Swing
PDF
Java OOP Programming language (Part 6) - Abstract Class & Interface
PDF
Java OOP Programming language (Part 5) - Inheritance
PDF
Java OOP Programming language (Part 4) - Collection
PDF
Java OOP Programming language (Part 3) - Class and Object
PDF
Java OOP Programming language (Part 1) - Introduction to Java
PDF
Javascript & DOM - Part 1- Javascript Tutorial for Beginners with Examples
PDF
Aggregate rank bringing order to web sites
DOC
How to succeed in graduate school
PDF
Google
PDF
E miner
PDF
Data preparation for mining world wide web browsing patterns (1999)
PDF
Consumer acceptance of online banking an extension of the technology accepta...
DOCX
When Do People Help
DOC
Mc Nemar
DOCX
Correlation Example
DOC
Sem Ski Amos
Class Diagram | OOP and Design Patterns by Oum Saokosal
Android app development - Java Programming for Android
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 7) - Swing
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 1) - Introduction to Java
Javascript & DOM - Part 1- Javascript Tutorial for Beginners with Examples
Aggregate rank bringing order to web sites
How to succeed in graduate school
Google
E miner
Data preparation for mining world wide web browsing patterns (1999)
Consumer acceptance of online banking an extension of the technology accepta...
When Do People Help
Mc Nemar
Correlation Example
Sem Ski Amos

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Encapsulation theory and applications.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
A comparative analysis of optical character recognition models for extracting...
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Encapsulation theory and applications.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The AUB Centre for AI in Media Proposal.docx
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Chapter 6 OOP (Revision)

  • 1. Object-Oriented Programming with Java Oum Saokosal , Head of IT Department National Polytechnic Institute of Cambodia Tel: (855)-12-417214 E-mail: [email protected]
  • 2. Chapter 6 Objects and Classes (Revision) OOP Classes Objects Constructors Accessing Object’s Data and Methods
  • 3. Object-Oriented Programming Why learning OOP? Java is a pure OOP OOP provides more flexibility, modularity, clarity, reusability Other Programming: C++, C#, VB .NET, ActionScript 3.0, Ruby etc. also use OOP. 3 concepts of OOP: Class Encapsulation Class Inheritance Polymorphism
  • 4. Classes (1) What is a class? A class is similar to a template, blueprint or symbol (in Adobe Flash). A class creates many objects. Class Objects
  • 5. Classes (2) In a class, there are : Data Fields (Properties) Behavior: Constructors Methods public class Student { private int id, String name; public Student(){} public Student (int inputID, String inputName){ this.id = inputID; this.name = inputName; } public String toString(){ return id + name; } }
  • 6. Constructors (1) What is constructor? A constructor is to construct (create) objects from a class. public class Student { private int id, String name; public Student(){} public Student (int inputID,String inputName){ this.id = inputID; this.name = inputName; } public String toString(){ return id + name; } }
  • 7. Constructors (2) How to construct objects? Usually, we have many classes in a projects. So the student class will be created in other classes. To construct objects from student class: public class TestStudent { public static void main(String[] args){ Student stu; //To construct an object stu = new Student(); System.out.println(stu.toString()); } }
  • 8. Access Object’s Data and Methods To access method: public class TestStudent { public static void main(String[] args){ Student stu; //To construct an object stu = new Student(“123”,”Veasna”); System.out.println( stu.toString() ); } } To access data: Usually, We don’t access the data. If you like, you can do like : stu.id = 123 in case id is not private .