OOP Concept

  • View
    123

  • Download
    4

Embed Size (px)

Transcript

Java Presentation

Korea Software HRD Centerwww.kshrd.com.kh

Java

OOP?2. Class Object ?3. Encapsulation ?4. Inheritance?5. Abstraction (Abstract class Interface)6. Polymorphism ?3

4OOP OOP Object Oriented Programming OOP class Program OOP Program OOP ?Encapsulation Inheritance Polymorphism

4

5OOPClassObject ObjectJava Class Object Class ?Instance Variable ( Data Member ) Method Instance Variable Method Member Class

5

6OOPclass class-name{type instance-variable1;type instance-variable2;//.type instance-variableN;type methodname 1(parameter-list){//body of method }type methodname 2(parameter-list){//body of method }type methodname N(parameter-list){//body of method }

} Class

6

7OOPClass Vehicle{int passengers; //number of passengersint fuelcap; //fuel capacity in litersint kpl; //fuel consumption in kilometers per liter

} Class Class (Data type) Vehicle Objects Vehicle minivan = new Vehicle();

7

OOPObject Instance Class Object Object ?Object State BehaviorState Object Ex1: Ex2: Behavior Object Ex1: . Ex2: ATM .

8

9OOP ObjectsVehicle minivan = new Vehicle(); minivan Vehicle (Reference of Object) new operator Memory Object Reference Object Reference Object Memory new

9

10OOP Methodsret-type methName(param-list){//body of method}ret-type Method Class Method void methName Method param-list (,)

10

11EncapsulationEncapsulation OOP concept Field class access class variable class hide class access method getter() setter() Encapsulation ?

11

12EncapsulationField class Read-only Write-only.Class data code Encapsulation ? class class (store) Class data type field class code

12

13Encapsulation

public class TestJava {private int id;private String name;private int age;public void setId(int id){this.id=id;}public int getID(){return id;}public void setName(String name){this.name=name;}public String getName(){return name;}public void setAge(int age){if(age