제 4 장 클래스와 객체

  • Upload
    caine

  • View
    166

  • Download
    7

Embed Size (px)

DESCRIPTION

제 4 장 클래스와 객체. 객체지향 언어의 목적. 소프트웨어의 생산성 향상 컴퓨터 산업 발전에 따라 소프트웨어의 생명 주기 (life cycle) 단축 객체 지향 언어는 상속 , 다형성 , 객체 , 캡슐화 등 소프트웨어 재사용을 위한 여러 장치 내장 소프트웨어의 재사용과 부분 수정을 통해 소프트웨어를 다시 만드는 부담을 대폭 줄임으로써 소프트웨어의 생산성이 향상 실세계에 대한 쉬운 모델링 과거 수학 계산 / 통계 처리를 하는 등의 처리 과정 , 계산 절차가 중요 현재 - PowerPoint PPT Presentation

Citation preview

PowerPoint

4 1 JAVA Programming (life cycle) , , , / , ()

2

3

() , ,

: String name;int age;void speak();void eat();void study(); (field)(method) 4 : - 55 : , :

6String name;int age;void eat();void sleep();void love();String name;int age;void work();void cry();void laugh();Animal Human void eat ();void sleep();void love();String hobby;String job;class Animal {String name;int age;void eat() {...}void sleep() {...}void love() {...}}class Human extends Animal {String hobby;String job;void work() {...}void cry() {...}void laugh() {...}} :

!!!7 () (instance) : , : 100: , : : , :

8 9

, . ., , . .

, ,, , , , , : :47AB 45 A : 28O : 10 11

, publicpublic class PersonPerson class { } (field) public (constructor) (method) public 12 new new public static void main (String args[]) { Person aPerson; // aPerson aPerson = new Person(); // Person

aPerson.age = 30;// int i = aPerson.age; // 30 String s = aPerson.getName(); // }13 14

public class ClassExample {public static void main (String args[]) {Person aPerson = new Person("");

aPerson.age = 30;int i = aPerson.age;String s = aPerson.getName();}} . 15 4-1 : Goods Goods . String name, int price, numberOfStock, sold . Goods main() Goods camera . camera (name ) Nikon, (price) 400000, (numberOfStock) 30, (sold) 50 . .public class Goods {String name;int price;int numberOfStock;int sold;public static void main(String[] args) {Goods camera = new Goods();

camera.name = Nikon;camera.price = 400000;camera.numberOfStock = 30;camera.sold = 50;

System.out.println(" :" + camera.name);System.out.println(" :" + camera.price);System.out.println(" :" + camera.numberOfStock);System.out.println(" :" + camera.sold);}}16 :Nikon :400000 :30 :50 4-2 : MyExp 17 MyExp . MyExp base exp . 23 base 2, exp 3 . base exp . MyExp getValue() . getValue() base exp . MyExp base 2 exp 3 getValue() 8 .public class MyExp {int base;int exp;int getValue() {int res=1;for(int i=0; i