Object Oriented Programming. Kwangwoo Choi Department of Physics Kangwon National University Object Something perceptible by one or more of the senses, especially by vision or touch; a material thing. 2. OOP(Object Oriented Programming) 3. Abstract 4. Class 5. encapsulation 6. inheritance 7. polymorphism
noun : accountNum, password , restMoney, interest object name : account noun : accountNum, password , restMoney, interest verb: saveMoney , withdrawMoney , getRestMoney public class Account { private String accountNum = "422-01-0903895"; private String password = "12345678"; private long restMoney = 34123415; private float interest = 3.34F; public void saveMoney(long amount) { restMoney = restMoney + amount; } public void withdrawMoney(long amount) { restMoney = restMoney - amount; } public long getRestMoney() { return restMoney; public void setInterest(float newInterest) { interest = newInterest; }
Make Object Account x; x = new Account(); Account x= new Account() public class Bank { public static void main(String [] args) { Account x = new Account(); x.saveMoney(100); x.withdrawMoney(50); System.out.println(x.getRestMoney()); } }
Encapsulation private String creaditCardNo; // private member public class Encapsulation { private String creaditCardNo; // private member public void setCreaditCardNo(String str) { creaditCardNo = str; } public String getCreaditCardNo() { return creaditCardNo; } } • public • protected • default • private
Inheritance class Employee { String name; Date hireDate; Date dateOfBirth; } class Manager { String name; Date hireDate; Date dateOfBirth; String department; Employee subordinamtes []; class Employee { String name; Date hireDate; Date dateOfBirth; } class Manager extends Employee{ String department; Employee subordinamtes []; }