Object-Oriented Programming with Java Oum Saokosal , Head of IT Department National Polytechnic Institute of Cambodia Tel:...
Chapter 6 Objects and Classes (Revision) <ul><li>OOP </li></ul><ul><li>Classes </li></ul><ul><li>Objects </li></ul><ul><li...
Object-Oriented Programming <ul><li>Why learning OOP? </li></ul><ul><ul><li>Java is a pure OOP </li></ul></ul><ul><ul><li>...
Classes (1) <ul><li>What is a class? </li></ul><ul><ul><li>A class is similar to a template, blueprint or symbol (in Adobe...
Classes (2) <ul><li>In a class, there are : </li></ul><ul><ul><li>Data Fields (Properties) </li></ul></ul><ul><ul><li>Beha...
Constructors (1) <ul><li>What is constructor? </li></ul><ul><ul><li>A constructor is to construct (create) objects from a ...
Constructors (2) <ul><li>How to construct objects? </li></ul><ul><ul><li>Usually, we have many classes in a projects. So t...
Access Object’s Data and Methods <ul><li>To access method: </li></ul><ul><ul><li>public class TestStudent { </li></ul></ul...
End of Revision
Upcoming SlideShare
Loading in …5
×

Chapter 6 OOP (Revision)

2,392 views
2,187 views

Published on

Chapter 6 OOP (Revision)
Taught by Oum Saokosal, Head of Information Technology, National Polytechnic Institute of Cambodia

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,392
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
88
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Chapter 6 OOP (Revision)

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

×