1 / 8

Chapter 7 Object-Oriented Programing

Chapter 7 Object-Oriented Programing. Lecturer: Ty Rasmey Email:rasmeyt2@gmail.com. Overview. OOP Classes Objects Constructor Accessing an Object’s Data and Methods. Object-Oriented Programming. What is OOP? Modelling real-world object in software Why design application in this way?

Download Presentation

Chapter 7 Object-Oriented Programing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7Object-Oriented Programing Lecturer: Ty Rasmey Email:rasmeyt2@gmail.com

  2. Overview • OOP • Classes • Objects • Constructor • Accessing an Object’s Data and Methods

  3. Object-Oriented Programming • What is OOP? • Modelling real-world object in software • Why design application in this way? • We naturally classify objects into different types • By attempting to do this with software aim to make it more maintainable, understandable, easier to reuse • Other Programming: C++, C#, VB .NET, ActionScript, Ruby etc. also use OOP. • 3 Concepts of OOP • Class Encapsulation; protects and manages own information • Class Inheritance; software reuse • Polymorphism

  4. Class(1) • What is Class? • Class is a template or blueprint or model • A class creates many objects

  5. Class(2) • In a class, there are: • State; data field(also known as Properties) • Behaviour: • 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. Constructor(1) • What is Constructor? • A constructor to construct 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. Constructor(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. Accessing an 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 = 123in case id is not private.

More Related