Microsoft PowerPoint - lec4_1 [호환 모드]

Size: px
Start display at page:

Download "Microsoft PowerPoint - lec4_1 [호환 모드]"

Transcription

1 객체지향프로그래밍 - 클래스및객체 - 상속성및다형성 - 추상클래스 - 예외처리

2 클래스 (class) 객체지향개념 자료 (field) + 자료를처리할수있는루틴 (method) 객체생성 캡슐화 (encapsulation) 정보은폐 (Information hiding) 멤버필드와메소드를클래스의외부에서는접근을조정 상속 (Inheritance) 새로운클래스를정의할때, 이미존재하는클래스를바탕으로필요한속성만추가하여작성하는방법 슈퍼클래스, 서브클래스 2

3 객체지향프로그래밍의장점 생산성향성 객체를하드웨어의 IC 처럼재사용 자연적인모델링 재사용 보통사람들의생각을프로그래밍언어로표현 상속성, 클래스통합을통한코드재상용의극대화 유지보수의용이성 함수수정에있어주변에미치는영향이최소화됨 3

4 4 실세계의객체와컴퓨터상의객체

5 클래스선언과객체생성및사용 1. 공장 = 클래스 2. 물건생성 = 객체생성 3. 물건생성 = 객체사용 mypen.write() Pen mypen = new Pen() 중요특성및 기능추출 class Pen { String color; int price; void write() { System.out.println("Hello"); } } 5

6 실세계의객체와컴퓨터상의객체 예제 : CircleUser.java class CircleUser { public static void main(string args[]) { Circle c = new Circle(); c.setradius(7); System.out.println(c.getCircumference()); System.out.println(" 원면적 :"+ c.getarea()); } } 6

7 생성자 (constructor) 객체생성과패키지 클래스이름과동일한이름을갖는함수 생성자의리턴타입은기술하지않음 메모리공간할당및클래스멤버필드의초기화를위해서필요 디폴트생성자 (default constructor) 7

8 예제 : Circle2.java 1 class Circle { 2 protected int r; 3 public Circle() { 4 r = 0; 5 } 6 public Circle(int r) { 7 this.r = r; 8 } 9 10 } 8

9 특징 this 클래스내에서자기자신을가리키는레퍼런스 static으로선언된메소드에서는사용될수없다. 두가지목적으로사용 자기자신의멤버필드나메소드를명확히지시하기위해서사용 객체전체를함수의아규먼트로전달해야하는경우에사용 예제 : This.java 9 void a(int a) { 10 this.a = a; 11 b.dojob(this); 12 } 13 }.. 9

10 패키지 유사한클래스들의모임 package package_name; 패키지내에서클래스들은서로자유롭게다른클래스들을참조 다른패키지의클래스참조. import package _ name.class_ name; 10

11 Public 클래스 public 으로선언된경우 같은패키지내에서자유롭게사용. 다른패키지에서도자유롭게사용. public 으로선언되지않은경우 같은패키지내에서는자유롭게사용 다른패키지에서접근시에러가발생 11

12 PublicPoint.java package points public class PublicPoint class PointList PublicPoint.java package pointuser package pointuser class PointUser point.publicpoint p = new class PointUser2 point.pointlist p1 = new 12 Pointuser.java Pointuser2.java

13 객체간의의사소통 : 메시지패싱 자바언어에서메시지패싱 메시지패싱방법을사용 대부분의프로그래밍언어에서는함수호출을이용 Car Engine engine; Pedal pedal; Wheel wheel; Di Driver Car car; car.pedal.push() pedal push(){ } engine.powerup(); wheel speedup(){ } engine powerup(){ } wheel.speedup() 13

14 가시성 : 클래스내부접근 package class class class 상속 O O X O protected public private default 상속 O O X O class class 14

15 가시성 : 클래스외부접근 package class class X class O O X X 상속 protected public private default O X X class 상속 class 15

16 가시성예제 package points package points4 class Point int x, y ; public void move(..) { } Import points.point3d class Point3d int z ; public void move(..) { } 상속 상속 class Point3d int z ; public void move(..) { } class Point4d int w ; public void move(..) { } 16

17 오버로딩 (overloading) 연산자오버로딩 (Operator Overloading) 동일한연산자가자료의타입에따라다른작업을수행하는것 메소드오버로딩 (Method Overloading) 동일한이름을가지는메소드가여러개존재가능 동일클래스에서메소드이름이동일하지만시그네쳐가다름. 17

18 메소드시그네쳐 (signiture) 메소드이름, 매개변수수, 매개변수자료형 동일한메소드이름을사용하면컴파일러가 시그네쳐를이용하여구분 메서드이름이동일하고시그니쳐도동일하다면 컴파일에러발생 메소드리턴타입은시그니쳐에포함되지않음 18

19 오버로딩 (overloading) 19 1 class Overloading { 2 public void say() { 3 System.out.println("Hello?"); 4 } 6 publicvoidsay(stringmsg){ 7 System.out.println(msg); 8 } 10 public void say(string msg, int n) { 11 for(int i =0; i < n; i++) { 12 System.out.println(msg); t tl 13 } 14 } 16 public static void main(string args[]) { 17 Overloading a = new Overloading(); 18 a.say(); 19 a.say( say("how are you?");?); 20 a.say("i am fine.", 3);...

20 상속성 (inheritance) 상속및기타 기존에있는클래스를바탕으로다른특성을추가해새로운클래스를생성 단일상속성 (single inheritance) animal superclass, baseclass, parent class 상속 (extends) is a relationship 특별화 (specialization) 일반화 (generalization) animal human Subclass, derived class, child class 20

21 21

22 super super, super() 슈퍼클래스를지칭하는레퍼런스 상위클래스의멤버필드나메소드를지칭할때사용 super.attribute, super.method() super() 슈퍼클래스의생성자호출 상속받은클래스는생성자에서슈퍼클래스의생성자를호출 22

23 1 class Manager extends Employee { 2 String dept; 3 Employee subordinate[]; 4 5 public Manager(String name, String idnum, String dept) { 6 super(name, idnum); 7 this.dept = dept; 8 } 9} 23

24 특성 클래스의상속관계에서발생 Overriding 슈퍼클래스에있는메소드를서브클래스에서다른작업을하도록서브클래스에서동일한메소드이름으로재정의 24 class Employee { public void dojob() { System.out.println(" temployee "+name + " does his best."); } } class Manager extends Employee { public void dojob() { System.out.println("Manager "+name +" works hard with his subordinates in"+dept+" dept."); } }

25 상속과오버라이딩 A z AA void b() { b()..("a") } a 10 void b() { c()..("aa") AA) } a 20 void c() {..("C") } 25

26 상속과오버라이딩시주의 오버라이딩을사용할때메소드의시그니쳐는동일하면서메소드의리턴타입이다른경우에는컴파일시에에러가발생 static 으로선언한메소드는오버라이딩되지않음 26

27 27 1 class Point { 2 int x = 0, y = 0, color; 3 void move(int dx, int dy) { x += dx; y += dy; } 4 int getx(){returnx;} 5 int gety(){returny;} 6} 7 8 class RealPoint extends Point { 9 float x = 0.0f, y = 0.0f; 10 void move(int dx, int dy) { move((float)dx, (float)dy); } 11 void move(float dx, float dy) { x+=dx; y += dy; } 12 float getx(){returnx;} 13 float gety() (){ return y; } 14 }

28 Static 메소드오버아리딩 1 class Super { 2 static String greeting() { return "Goodnight"; } 3 String name() { return "Richard"; } 4 } 5 6 class Sub extends Super { 7 static String greeting() { return "Hello"; } 8 String name() { return "Dick"; } 9 } class MethodHiding { 12 public static void main(string[] args) { 13 Super s = new Sub(); 14 System.out.println(s.greeting() + ", " + s.name()); 15 } 16 } 28

29 정의 오버쉐도우 (overshadow) 동일한이름의필드가슈퍼클래스와서브클래스에동시에존재 오버쉐도우된멤버접근 super 레퍼런스 서브클래스를슈퍼클래스로형변환 오버라이드된메소드는형변환을통해접근할수없고 super 레퍼런스를통해서만접근. 29

30 예제 : Super.java 1 class SuperOne { 2 int a; 3 public SuperOne() { 4 a = 10; 5 } 6 7 public void print() { 8 System.out.println("I am SuperOne."); 9 } 10 } 11 30

31 12 class SubOne extends SuperOne { 13 int a; public SubOne() { 16 super(); 17 a = 20; 18 } public void print() { 21 System.out.println("I am SubOne."); 22 } 23 public int getsupera() { 25 return super.a; 26 } 27 public void dosuperprint() { 29 super.print(); 30 } 31

32 32 public static void main(string args[]) { 33 SubOne sub = new SubOne(); 34 System.out.println("sub.a = " + sub.a); 35 sub.print(); 36 System.out.println("((SuperOne)sub).a = " + ((SuperOne)sub).a); 37 ((SuperOne)sub).print(); 38 sub.dosuperprint(); 39 } 40 } 32

33 XYZ.java i=10; Class X print() ; msg = I am an X ; play() ; Class Y i=10; msg = I am an Y ; print() ; play() ; Class Z i=10; msg = I am an Z ; print() ; play() ; 33

34 다형성 (polymorphism) Poly = Many Morph = Forms Polymorphism = Many forms 과학자 화가 뉴튼스티븐호킹아인슈타인 레오나르도다빈치 고호피카소 다형적객체 (polymophic object) 34

35 다형성종류 Universal Parametric Inclusion (Subtyping) Polymorphism Ad-hoc Overloading Coercion 35

36 예, PolyA.java PolyB.java Class PolyA Class PolyB msg = I am PolyA!! work() { } msg = I am PolyB.. work() { } stack PolyB b() PolyA a() heap b.work() a.work() 36

37 예, PolyA2.java PolyB2.java Class PolyA2 Class PolyB2 stack msg = IamPolyA!! init() { work() } work() { } msg = I ampolyb PolyB.. work() { } PolyB2 b() PolyA2 a =new PolyB2() heap b.init() => work() a.init() 37

38 추상클래스 (abstract class) 추상클래스 (abstract class) 특성이구체적으로구현되지않는클래스 new 연산자로객체를생성할수없음. 추상메소드를가지는모든클래스 추상메소드 메소드의인터페이스만정의되어있는메소드 메소드의리턴타입부분앞에 abstract라는키워드를기술 추상클래스로부터상속받는경우에서브클래스는추상메소드를구현 (implement) 몸체완성 38

39 추상클래스예제 Shape.java public abstract class Shape { public abstract double area( ); public abstract double circumference( ); } - 상속 - 상속 - 추상메소드구현 - 추상메소드구현 Circle.java Rectangle.java 39

40 40 결과 1 class ShapeUser { 2 3 public static void main(string arg[]) { 4 Shape shape[] = new Shape[3]; 5 6 shape[0] = new Circle(5); 7 shape[1] = new Circle(7); 8 shape[2] = new Rectangle(9, 5); 9 10 System.out.println("shape[0]'s area = " + shape[0].area()); area()); 11 System.out.println("shape[1]'s area = " + shape[1].area()); 12 System.out.println( println("shape[2]'s s area ="+ shape[2].area()); C:\> java ShapeUser shape[0]'s area = shape[1]'s area =

41 인터페이스 인터페이스 (interface) 추상클래스와유사 다중상속지원 [ interfacemodifier ] interface name [ extends name ] { [ interfacefieldmodifier ] type name; [ interfacemethodmodifier ] returntype name ( argumentlist ) ; } 41

42 예제 : Trash.java 1 public class Trash extends Thing { 2 Trash() { 3 super(" 쓰레기 "); 4 } 5 } 42

43 예제 : Shop.java 인터페이스 (interface) 8 public void sell(valuable v, String goods) { 9 System.out.print(name +" 에서 "); 10 System.out.print(v.value() + " 원어치 "); 14 public static void main(string args[]) { 15 Shop myshop = new Shop(" 숭실슈퍼 "); 16 Money money = new Money(5000); 17 Watch watch = new Watch(" 로렉스 "); 21 myshop.sell(money, " 과자 "); 22 myshop.sell(watch, " 음료수 "); 43

44 Thing.java 1 public abstract class Thing { 2 String name; 4 Thing(String name) { 5 this.name = name; 6 } 7 } Valuable.java 1 interface Valuable { 2 public int value() ; 3 } 44 Watch.java public class Watch extends Thing implements Valuable { String brand; Watch(String b) { super(" 시계 "); brand = b; } public int value() { return 10000; } } Money.java public class Money extends Thing implements Valuable { int value; Money(int value) { super(" 돈 "); this.value = value; } public int value() { return value; } }

45 new Shop( 슈퍼 ); new Money(5000); new Watch( 로렉스 )) new Trash() ; Shop class name = 슈퍼 Money class name = 돈 value = 5000 return 5000 Watch class name = 시계 brabd = 로렉스 return Trash class name = 쓰레기 45

46 예 )DrawableCircle l 인터페이스 (interface) 46

47 인터페이스특성 필드는디폴드로 static, final 로선언 필드의값을변경, 컴파일에러 implements : 상속념 임플리멘츠한서브클래스는인터페이스의필드를상속 인터페이스의상속은클래스와마찬가지로키워드 extends 를사용 47

48 final 클래스 static 과 final 의의미 더이상상속을통해서재사용할수없음 final 클래스를상속받으려는클래스는컴파일시에에러가발생 클래스앞에 final 키워드사용 public final class FinalClass{. } final 메소드 final 이메소드에선언된경우, 오버라이딩이불가능 메소드앞에 final 키워드사용 public final void print(){. } 48

49 final 멤버필드 static 과 final 의의미 값을변경할수없는상수의의미 final 필드는값을초기화만할수있고, 새로운값을할당할수는없음 필드앞에 final 키워드사용 public final int a = 10; static 멤버필드 객체들간의전역변수처럼사용됨 클래스이름으로접근한다.(ex : Color.red) 멤버필드앞에 static 키워드사용 static int a = 3; 49

50 static 메소드 클래스메소드 static 과 final 의의미 메소드앞에 static 키워드사용 public final static void sayhello(string arg){. } 주의 this, super 를사용할수없음 static 이아닌멤버필드는접근할수없음 50

51 Object 클래스 자바에서중요한클래스 모든자바클래스의슈퍼클래스 extends Object 를쓰지않아도자동적으로상속 Object 클래스들의메소드 protected Object clone() public boolean equals(object obj) public int hashcode() 51

52 자바에서중요한클래스 데이터타입클래스 52

53 예외처리 예외처리 간단한에러 ( 예외 ) 가발생하였을때, 오류를바로잡아서계속수행할수있도록오류를처리 예외혹은예외상황 - 심각하지않은에러 C 언어에서예외처리 일반함수나시스템콜은음수값을혹은 0 을리턴 필요할경우 errno에값을할당해서에러의타입을알리기도함 53

54 3 main(int argc, char* argv[]) { 11 if((i = divide(a)) < 0) 12 printf("error!!"); 13 else 14 printf("successful!: answer is %d", i); 17 int divide(int x) { 18 switch(x) { 19 case 0: 20 return -1; /* 에러가발생하기전에 -1 값을리턴. */ 21 case 1: 22 return -2; /* 에러가발생하기전에 -2값을리턴. */ 23 defaults: 24 break; 25 } 26 return 100/(x*(x-1)); ( 1)).. 54

55 자바에서예외처리 1. Exception 클래스를정의 2. 예외가발생할조건을만족하면 Exception 클래스를 throw 3. try-catch 문을이용해서예외가발생하는경우에문제점을해결 55

56 예외클래스종류 자바에서예외 (Exception) 는클래스로표현 모든예외타입 (exception type) 은 Throwable 클래스나이것의서브클래스로부터상속 checked exception 메소드가선언한예외를 throw 하는지를컴파일러가체크 try-catch문을사용해야한다. unchecked exception RuntimeException이나 Error로부터상속받는표준런타임예외와에러 try-catch 문을사용하지않아도컴파일시에에러가발생하지않음 예외타입은클래스이기때문에생성자, 멤버필드, 메소드등을가질수있음 56

57 예외클래스만들기 예외처리 Exception 클래스를상속받아야한다. Checked Exception 와 UncheckedException public class DivideZeroException extends Exception { 2 private String reason; 3 4 DivideZeroException() { 5 reason = "Divide by zero"; 6 } 7 8 public String tostring() { 9 return reason; 10 } 11 }

58 throws 예외처리 checked exception 을메소드이름뒤에선언 public int dosomething(int x) throws Exception1, Exception2 { } throw 예외는 throw 문장을이용해서발생 throw new Exception1(); throws를혼동하기쉬움 58

59 예외처리 예제 : Divider.java : Exception 클래스를 throw 59 1 public class Divider { 2 3 public Divider() id { 4 5 } 6 7 public int divide(int x) throws DivideZeroException { 8 switch(x) { 9 case 0: 10 throw new DivideZeroException(); id 11 case 1: 12 throw new DivideZeroException(); 13 defaults: 14 ; 15 } 16 return (int)(100/(x*(x-1))); 17 } 18 }

60 try-catch-finally 예외처리 예외가발생할수있는문장들을 try 문블럭에기술 수행도중에예외가발생하면 catch 문으로제어가넘어감. catch 문은여러개가존재할수있음 finally 문은예외발생여부에관계없이항상수행. 60

61 예외처리 61 1 public class TestException { 2 3 public TestException() { } 4 5 public static void main(string[] args) { 6 int a; 7 8 Divider t = new Divider(); 9 try { 10 a = Integer.parseInt(args[0]); 11 System.out.println("successful!: answer is "+ t.divide(a)); 12 } catch(dividezeroexception e) { 13 System.out.println("error!!: " + e); 14 } catch(exception ex) { 15 System.out.println("error!!: t tl " + ex); 16 }..

62 예외처리 JDK 에서제공되는예외 Exception 클래스상속관계 62

63 예외처리 JDK 에서제공되는예외클래스들의예 ArithmeticException 0으로나누는경우에주로발생하는예외상황 ArithmeticException 은 RuntimeException 으로부터상속받은예외클래스 ArrayIndexOutofBoundsException 배열의크기보다큰원소를접근하려고할때발생되는예외 NegativeArraySizeException 배열의크기가음수로된경우에발생하는예외 NullPointerException ti 생성되지않은객체를이용해서객체의멤버를접근하는경우에발생하는예외 63

gnu-lee-oop-kor-lec06-3-chap7

gnu-lee-oop-kor-lec06-3-chap7 어서와 Java 는처음이지! 제 7 장상속 Super 키워드 상속과생성자 상속과다형성 서브클래스의객체가생성될때, 서브클래스의생성자만호출될까? 아니면수퍼클래스의생성자도호출되는가? class Base{ public Base(String msg) { System.out.println("Base() 생성자 "); ; class Derived extends Base

More information

JAVA PROGRAMMING 실습 08.다형성

JAVA PROGRAMMING 실습 08.다형성 2015 학년도 2 학기 1. 추상메소드 선언은되어있으나코드구현되어있지않은메소드 abstract 키워드사용 메소드타입, 이름, 매개변수리스트만선언 public abstract String getname(); public abstract void setname(string s); 2. 추상클래스 abstract 키워드로선언한클래스 종류 추상메소드를포함하는클래스

More information

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 객체지향프로그래밍 IT CookBook, 자바로배우는쉬운자료구조 q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 q 객체지향프로그래밍의이해 v 프로그래밍기법의발달 A 군의사업발전 1 단계 구조적프로그래밍방식 3 q 객체지향프로그래밍의이해 A 군의사업발전 2 단계 객체지향프로그래밍방식 4 q 객체지향프로그래밍의이해 v 객체란무엇인가

More information

PowerPoint Presentation

PowerPoint Presentation Class - Property Jo, Heeseung 목차 section 1 클래스의일반구조 section 2 클래스선언 section 3 객체의생성 section 4 멤버변수 4-1 객체변수 4-2 클래스변수 4-3 종단 (final) 변수 4-4 멤버변수접근방법 section 5 멤버변수접근한정자 5-1 public 5-2 private 5-3 한정자없음

More information

Microsoft PowerPoint - 2강

Microsoft PowerPoint - 2강 컴퓨터과학과 김희천교수 학습개요 Java 언어문법의기본사항, 자료형, 변수와상수선언및사용법, 각종연산자사용법, if/switch 등과같은제어문사용법등에대해설명한다. 또한 C++ 언어와선언 / 사용방법이다른 Java의배열선언및사용법에대해서설명한다. Java 언어의효과적인활용을위해서는기본문법을이해하는것이중요하다. 객체지향의기본개념에대해알아보고 Java에서어떻게객체지향적요소를적용하고있는지살펴본다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Lab 4 ADT Design 클래스로정의됨. 모든객체들은힙영역에할당됨. 캡슐화 (Encapsulation) : Data representation + Operation 정보은닉 (Information Hiding) : Opertion부분은가려져있고, 사용자가 operation으로만사용가능해야함. 클래스정의의형태 public class Person { private

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 11 장상속 이번장에서학습할내용 상속이란? 상속의사용 메소드재정의 접근지정자 상속과생성자 Object 클래스 종단클래스 상속을코드를재사용하기위한중요한기법입니다. 상속이란? 상속의개념은현실세계에도존재한다. 상속의장점 상속의장점 상속을통하여기존클래스의필드와메소드를재사용 기존클래스의일부변경도가능 상속을이용하게되면복잡한 GUI 프로그램을순식간에작성

More information

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1); void method() 2); void method1() public class Test 3); args) A 제 10 장상속 예제 1) ConstructorTest.java class Parent public Parent() super - default"); public Parent(int i) this("hello"); super(int) constructor" + i); public Parent(char c) this(); super(char) constructor

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

슬라이드 1

슬라이드 1 UNIT 16 예외처리 로봇 SW 교육원 3 기 최상훈 학습목표 2 예외처리구문 try-catch-finally 문을사용핛수있다. 프로그램오류 3 프로그램오류의종류 컴파일에러 (compile-time error) : 컴파일실행시발생 럮타임에러 (runtime error) : 프로그램실행시발생 에러 (error) 프로그램코드에의해서해결될수없는심각핚오류 ex)

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 필드만있는클래스 텔레비젼 2 예제 1. 필드만있는클래스 3 예제 2. 여러개의객체생성하기 4 5 예제 3. 메소드가추가된클래스 public class Television { int channel; // 채널번호 int volume; // 볼륨 boolean

More information

JAVA PROGRAMMING 실습 09. 예외처리

JAVA PROGRAMMING 실습 09. 예외처리 2015 학년도 2 학기 예외? 프로그램실행중에발생하는예기치않은사건 예외가발생하는경우 정수를 0으로나누는경우 배열의크기보다큰인덱스로배열의원소를접근하는경우 파일의마지막부분에서데이터를읽으려고하는경우 예외처리 프로그램에문제를발생시키지않고프로그램을실행할수있게적절한조치를취하는것 자바는예외처리기를이용하여예외처리를할수있는기법제공 자바는예외를객체로취급!! 나뉨수를입력하시오

More information

Cluster management software

Cluster management software 자바네트워크프로그래밍 (OCJP 국제공인자격취득중심 ) 충북대학교 최민 기본예제 예외클래스를정의하고사용하는예제 class NewException extends Exception { public class ExceptionTest { static void methoda() throws NewException { System.out.println("NewException

More information

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345]) 예외와예외클래스 예외처리 514760-1 2016 년가을학기 12/08/2016 박경신 오류의종류 에러 (Error) 하드웨어의잘못된동작또는고장으로인한오류 에러가발생되면 JVM실행에문제가있으므로프로그램종료 정상실행상태로돌아갈수없음 예외 (Exception) 사용자의잘못된조작또는개발자의잘못된코딩으로인한오류 예외가발생되면프로그램종료 예외처리 추가하면정상실행상태로돌아갈수있음

More information

Microsoft PowerPoint - CSharp-10-예외처리

Microsoft PowerPoint - CSharp-10-예외처리 10 장. 예외처리 예외처리개념 예외처리구문 사용자정의예외클래스와예외전파 순천향대학교컴퓨터학부이상정 1 예외처리개념 순천향대학교컴퓨터학부이상정 2 예외처리 오류 컴파일타임오류 (Compile-Time Error) 구문오류이기때문에컴파일러의구문오류메시지에의해쉽게교정 런타임오류 (Run-Time Error) 디버깅의절차를거치지않으면잡기어려운심각한오류 시스템에심각한문제를줄수도있다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 인터페이스 배효철 th1g@nate.com 1 목차 인터페이스의역할 인터페이스선언 인터페이스구현 인터페이스사용 타입변환과다형성 인터페이스상속 디폴트메소드와인터페이스확장 2 인터페이스의역할 인터페이스란? 개발코드와객체가서로통신하는접점 개발코드는인터페이스의메소드만알고있으면 OK 인터페이스의역할 개발코드가객체에종속되지않게 -> 객체교체할수있도록하는역할 개발코드변경없이리턴값또는실행내용이다양해질수있음

More information

Semantic Consistency in Information Exchange

Semantic Consistency in Information Exchange 제 6 장제어 (Control) 6.1 구조적프로그래밍 (Structured Programming) 6.2 예외 (Exceptions) Reading Chap. 7 숙대창병모 1 6.1 구조적프로그래밍 숙대창병모 2 Fortran 제어구조 10 IF (X.GT. 0.000001) GO TO 20 11 X = -X IF (X.LT. 0.000001) GO TO

More information

Design Issues

Design Issues 11 COMPUTER PROGRAMMING INHERIATANCE CONTENTS OVERVIEW OF INHERITANCE INHERITANCE OF MEMBER VARIABLE RESERVED WORD SUPER METHOD INHERITANCE and OVERRIDING INHERITANCE and CONSTRUCTOR 2 Overview of Inheritance

More information

JAVA PROGRAMMING 실습 07. 상속

JAVA PROGRAMMING 실습 07. 상속 상속 부모클래스에정의된필드와메소드를자식클래스가물려받는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정 = 오버라이딩구체화 class Phone 전화걸기전화받기 class MobilePhone 전화걸기전화받기무선기지국연결배터리충전하기

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 인터페이스, 람다식, 패키지 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 홈네트워킹 public interface RemoteControl { public void turnon(); // 가전제품을켠다. public void turnoff(); // 가전제품을끈다. 인터페이스를구현 public class Television

More information

C++ Programming

C++ Programming C++ Programming 예외처리 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 예외처리 2 예외처리 예외처리 C++ 의예외처리 예외클래스와객체 3 예외처리 예외를처리하지않는프로그램 int main() int a, b; cout > a >> b; cout

More information

No Slide Title

No Slide Title 상속 이충기 명지대학교컴퓨터공학과 상속 Q: 건설회사는기존아파트와조금다르거나추가적인특징들을가진새아파트를지을때어떻게하는가? A: 2 상속 상속 (inheritance) 은클래스들을연관시키는자연스럽고계층적인방법이다. 상속은객체지향프로그래밍의가장중요한개념중의하나이다. 상속은 은 이다 라는관계 (is-a relationship) 를나타낸다. 이관계를적용하여클래스들을상하관계로연결하는것이상속이다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 2... ( ). ( ). @ vs. logic data method variable behavior attribute method field Flow (Type), ( ) member @ () : C program Method A ( ) Method B ( ) Method C () program : Java, C++, C# data @ Program

More information

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345]) Class Class, Collections 514770-1 2017 년봄학기 3/22/2017 박경신 클래스 (Class) 객체의속성과행위선언 객체의설계도혹은틀 객체 (Object) 클래스의틀로찍어낸실체 메모리공간을갖는구체적인실체 클래스를구체화한객체를인스턴스 (instance) 라고부름 객체와인스턴스는같은뜻으로사용 클래스구조 클래스접근권한, public 다른클래스들에서이클래스를사용하거나접근할수있음을선언

More information

JAVA PROGRAMMING 실습 02. 표준 입출력

JAVA PROGRAMMING 실습 02. 표준 입출력 # 왜생겼나요..? : 절차지향언어가가진단점을보완하고다음의목적을달성하기위해..! 1. 소프트웨어생산성향상 객체지향소프트웨어를새로만드는경우이미만든개체지향소프트웨어를상속받거나객체를 가져다재사용할수있어부분수정을통해소프트웨어를다시만드는부담줄임. 2. 실세계에대한쉬운모델링 실세계의일은절차나과정보다는일과관련된많은물체들의상호작용으로묘사. 캡슐화 메소드와데이터를클래스내에선언하고구현

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

제11장 프로세스와 쓰레드

제11장 프로세스와 쓰레드 제9장자바쓰레드 9.1 Thread 기초 (1/5) 프로그램 명령어들의연속 (a sequence of instruction) 프로세스 / Thread 실행중인프로그램 (program in execution) 프로세스생성과실행을위한함수들 자바 Thread 2 9.1 Thread 기초 (2/5) 프로세스단위작업의문제점 프로세스생성시오버헤드 컨텍스트스위치오버헤드

More information

Network Programming

Network Programming Part 5 확장된 Network Programming 기술 1. Remote Procedure Call 2. Remote Method Invocation 3. Object Request Broker 2. Java RMI

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 상속 배효철 th1g@nate.com 1 목차 상속개념 클래스상속 부모생성자호출 메소드재정의 final 클래스와 final 메소드 protected 접근제한자 타입변환과다형성 추상클래스 2 상속개념 상속 (Inheritance) 이란? 현실세계 : 부모가자식에게물려주는행위 부모가자식을선택해서물려줌 객체지향프로그램 : 자식 ( 하위, 파생 ) 클래스가부모 (

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 오류처리 손시운 ssw5176@kangwon.ac.kr 오류메시지를분석한다. 오류메시지에서많은내용을알수있다. 2 디버깅 디버거를사용하면프로그램에서쉽게오류를감지하고진단할수있다. 디버거는중단점을설정하여서프로그램의실행을제어할수있으며문장 단위로실행하거나변수의값을살펴볼수있다. 3 이클립스에서디버깅 4 이클립스에서디버깅 5 이클립스의디버깅명령어 6 예외처리

More information

슬라이드 1

슬라이드 1 UNIT 12 상속과오버라이딩 로봇 SW 교육원 2 기 최상훈 학습목표 2 클래스를상속핛수있다. 메소드오버라이딩을사용핛수있다. 패키지선언과 import 문을사용핛수있다. 상속 (inheritance) 3 상속이란 기존의클래스를기반으로새로운클래스를작성 두클래스를부모와자식으로관계를맺어주는것 자식은부모의모든멤버를상속받음 연관된일렦의클래스에대핚공통적인규약을정의 class

More information

PowerPoint Template

PowerPoint Template 10. 예외처리 대구가톨릭대학교 IT 공학부 소프트웨어공학연구실 목차 2 10.1 개요 10.2 C++ 의예외처리 10.3 Java 의예외처리 10.4 Ada 의예외처리 10.1 예외처리의개요 (1) 3 예외 (exception) 오버플로나언더플로, 0 으로나누기, 배열첨자범위이탈오류와같이프로그램실행중에비정상적으로발생하는사건 예외처리 (exception handling)

More information

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D> Power Java 제 8 장클래스와객체 I 이번장에서학습할내용 클래스와객체 객체의일생직접 메소드클래스를 필드작성해 UML 봅시다. QUIZ 1. 객체는 속성과 동작을가지고있다. 2. 자동차가객체라면클래스는 설계도이다. 먼저앞장에서학습한클래스와객체의개념을복습해봅시다. 클래스의구성 클래스 (class) 는객체의설계도라할수있다. 클래스는필드와메소드로이루어진다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 예외처리 배효철 th1g@nate.com 1 목차 예외와예외클래스 실행예외 예외처리코드 예외종류에따른처리코드 자동리소스닫기 예외처리떠넘기기 사용자정의예외와예외발생 예외와예외클래스 구문오류 예외와예외클래스 구문오류가없는데실행시오류가발생하는경우 예외와예외클래스 import java.util.scanner; public class ExceptionExample1

More information

C++ Programming

C++ Programming C++ Programming 상속과다형성 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 상속의이해 상속과다형성 다중상속 2 상속과다형성 객체의이해 상속클래스의객체의생성및소멸 상속의조건 상속과다형성 다중상속 3 상속의이해 상속 (Inheritance) 클래스에구현된모든특성 ( 멤버변수와멤버함수 )

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 7 장클래스와객체 이번장에서학습할내용 객체지향이란? 객체 메시지 클래스 객체지향의장점 String 클래스 객체지향개념을완벽하게이해해야만객체지향설계의이점을활용할수있다. 실제세계는객체로이루어진다. 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 절차지향과객체지향 절차지향프로그래밍 (procedural programming): 문제를해결하는절차를중요하게생각하는방법

More information

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Microsoft PowerPoint 자바-기본문법(Ch2).pptx 자바기본문법 1. 기본사항 2. 자료형 3. 변수와상수 4. 연산자 1 주석 (Comments) 이해를돕기위한설명문 종류 // /* */ /** */ 활용예 javadoc HelloApplication.java 2 주석 (Comments) /* File name: HelloApplication.java Created by: Jung Created on: March

More information

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå 기초통계프로그래밍 클래스, 객체, 변수, 메소드 hmkang@hallym.ac.kr 금융정보통계학과 강희모 ( 금융정보통계학과 ) 기초통계프로그래밍 1 / 26 자바구성파일 소스파일 소스파일 : 사용자가직접에디터에입력하는파일로자바프로그램언어가제공하는형식으로제작 소스파일의확장자는.java 임 컴파일 : javac 명령어를이용하여프로그래머가만든소스파일을컴파일하여실행파일.class

More information

Microsoft PowerPoint - chap11

Microsoft PowerPoint - chap11 10 장객체 - 지향프로그래밍 II 상속 상속 (Inheritance) 상속이란무엇인가? 기존의클래스로부터새로운클래스를유도하는것 자식클래스는부모클래스의메쏘드와데이터를상속 자식클래스에새로운변수나메쏘드를추가할수있다. 기존클래스 부모클래스 (parent class), 수퍼클래스 (superclass), 기반클래스 (base class) 유도클래스 자식클래스 (child

More information

01-OOPConcepts(2).PDF

01-OOPConcepts(2).PDF Object-Oriented Programming Concepts Tel: 02-824-5768 E-mail: hhcho@selabsoongsilackr? OOP (Object) (Encapsulation) (Message) (Class) (Inheritance) (Polymorphism) (Abstract Class) (Interface) 2 1 + = (Dependency)

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 손시운 ssw5176@kangwon.ac.kr 실제세계는객체로이루어진다. 2 객체와메시지 3 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 4 객체 5 객체란? 객체 (Object) 는상태와동작을가지고있다. 객체의상태 (state) 는객체의특징값 ( 속성 ) 이다. 객체의동작 (behavior) 또는행동은객체가취할수있는동작

More information

PowerPoint Presentation

PowerPoint Presentation Class : Method Jo, Heeseung 목차 section 1 생성자 (Constructor) section 2 생성자오버로딩 (Overloading) section 3 예약어 this section 4 메소드 4-1 접근한정자 4-2 클래스메소드 4-3 final, abstract, synchronized 메소드 4-4 메소드반환값 (return

More information

Microsoft PowerPoint - java2 [호환 모드]

Microsoft PowerPoint - java2 [호환 모드] 10 장객체- 지향프로그래밍 II 창병모 1 상속 창병모 2 상속 (Inheritance) 상속이란무엇인가? 기존의클래스로부터새로운클래스를유도하는것 자식클래스는부모클래스의메쏘드와데이터를상속 자식클래스에새로운변수나메쏘드를추가할수있다. 기존클래스 부모클래스 (parent class), 수퍼클래스 (superclass), 기반클래스 (base class) 유도클래스

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 3 if, if else, if else if, switch case for, while, do while break, continue : System.in, args, JOptionPane for (,, ) @ vs. logic data method variable Data Data Flow (Type), ( ) @ Member field

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 상속 손시운 ssw5176@kangwon.ac.kr 상속이란? 상속의개념은현실세계에도존재한다. 2 상속의장점 상속의장점 상속을통하여기존클래스의필드와메소드를재사용 기존클래스의일부변경도가능 상속을이용하게되면복잡한 GUI 프로그램을순식간에작성 상속은이미작성된검증된소프트웨어를재사용 신뢰성있는소프트웨어를손쉽게개발, 유지보수 코드의중복을줄일수있다. 3

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 1 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

자바 프로그래밍

자바 프로그래밍 5 (kkman@mail.sangji.ac.kr) (Class), (template) (Object) public, final, abstract [modifier] class ClassName { // // (, ) Class Circle { int radius, color ; int x, y ; float getarea() { return 3.14159

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 public class Person{ public String name; public int age; } public Person(){ } public Person(String s, int a){ name = s; age = a; } public String getname(){ return name; } @ 객체의선언 public static void main(string

More information

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2 예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 kkman@sangji.ac.kr 2 예외 (exception) 실행시간에발생하는에러 (run-time error) 프로그램의비정상적인종료잘못된실행결과 예외처리 (exception handling) 기대되지않은상황에대해예외를발생야기된예외를적절히처리 (exception handler) kkman@sangji.ac.kr

More information

Microsoft PowerPoint - java1 [호환 모드]

Microsoft PowerPoint - java1 [호환 모드] 10 장객체 - 지향프로그래밍 I 창병모 1 10.1 객체 - 지향개념 창병모 2 객체지향 : 동기 프로그램에서실세계객체들을시뮬레이션 창병모 3 객체 (Object) 객체 상태 (state) 객체에대한데이터 행동 (behavior)- 할 ( 될 ) 수있는연산혹은동작 예 : 은행계좌 계좌번호 현재잔액 입금 출금 창병모 4 객체와클래스 객체 Object= 데이터

More information

Microsoft PowerPoint - additional08.ppt [호환 모드]

Microsoft PowerPoint - additional08.ppt [호환 모드] 8. 상속과다형성 (polymorphism) 상속된객체와포인터 / 참조자의관계 정적바인딩과동적바인딩 virtual 소멸자 Jong Hyuk Park 상속의조건 public 상속은 is-a 관계가성립되도록하자. 일반화 ParttimeStd 구체화 2 상속의조건 잘못된상속의예 현실세계와완전히동떨어진모델이형성됨 3 상속의조건 HAS-A( 소유 ) 관계에의한상속!

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 오류처리 손시운 ssw5176@kangwon.ac.kr 오류메시지를분석한다. 오류메시지에서많은내용을알수있다. 2 디버깅 디버거를사용하면프로그램에서쉽게오류를감지하고진단할수있다. 디버거는중단점을설정하여서프로그램의실행을제어할수있으며문장 단위로실행하거나변수의값을살펴볼수있다. 3 이클립스에서디버깅 4 이클립스에서디버깅 5 이클립스의디버깅명령어 6 예외처리

More information

JVM 메모리구조

JVM 메모리구조 조명이정도면괜찮조! 주제 JVM 메모리구조 설미라자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조장. 최지성자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조원 이용열자료조사, 자료작성, PPT 작성, 보고서작성. 이윤경 자료조사, 자료작성, PPT작성, 보고서작성. 이수은 자료조사, 자료작성, PPT작성, 보고서작성. 발표일 2013. 05.

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 14. 상속 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 상속의기본 파생클래스와생성자 protected: 제한자 멤버함수의재정의 상속되지않는함수들 상속을이용한프로그래밍

More information

C++ Programming

C++ Programming C++ Programming 클래스와데이터추상화 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 객체지향프로그래밍 클래스와객체 2 객체지향프로그래밍 객체지향언어 (Object-Oriented Language) 프로그램을명령어의목록으로보는시각에서벗어나여러개의 독립된단위, 즉 객체 (Object) 들의모임으로파악

More information

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx 2018 학년도 1 학기 JAVA 프로그래밍 II 514760-1 2018 년봄학기 5/10/2018 박경신 Lab#1 (ImageTest) Lab#1 은영상파일 (Image) 을읽어서정보를출력 Java Tutorials Lesson: Working with Images https://docs.oracle.com/javase/tutorial/2d/images/index.html

More information

5장.key

5장.key JAVA Programming 1 (inheritance) 2!,!! 4 3 4!!!! 5 public class Person {... public class Student extends Person { // Person Student... public class StudentWorker extends Student { // Student StudentWorker...!

More information

PowerPoint Presentation

PowerPoint Presentation 자바프로그래밍 1 클래스와메소드심층연구 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 접근제어 class A { private int a; int b; public int c; // 전용 // 디폴트 // 공용 public class Test { public static void main(string args[]) { A obj = new

More information

9장.예외와 단정

9장.예외와 단정 예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 [2/28] 예외 (exception) 실행시간에발생하는에러 (run-time error) 프로그램의비정상적인종료잘못된실행결과 예외처리 (exception handling) 기대되지않은상황에대해예외를발생 야기된예외를적절히처리 (exception handler) [3/28] 단정 (assertion)

More information

Microsoft PowerPoint - lec12 [호환 모드]

Microsoft PowerPoint - lec12 [호환 모드] 제네릭 제네릭클래스 제네릭인터페이스 제네릭메소드 형매개변수의제한 어노테이션 어노테이션형태시스템정의어노테이션사용자정의어노테이션 kkman@sangji.ac.kr 2 제네릭 (generic) 클래스나메소드에자료형을매개변수형식으로사용할수있는기능 자료형과무관하게알고리즘을기술 예전에작성한알고리즘을쉽게재사용가능 어노테이션 (annotation) 프로그램요소에다양한종류의속성정보를추가하기위해서사용

More information

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 (   ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각 JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( http://java.sun.com/javase/6/docs/api ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각선의길이를계산하는메소드들을작성하라. 직사각형의가로와세로의길이는주어진다. 대각선의길이는 Math클래스의적절한메소드를이용하여구하라.

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 5 장생성자와접근제어 1. 객체지향기법을이해한다. 2. 클래스를작성할수있다. 3. 클래스에서객체를생성할수있다. 4. 생성자를이용하여객체를초기화할수 있다. 5. 접근자와설정자를사용할수있다. 이번장에서만들어볼프로그램 생성자 생성자 (constructor) 는초기화를담당하는함수 생성자가필요한이유 #include using namespace

More information

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class Linux JAVA 1. http://java.sun.com/j2se/1.4.2/download.html J2SE 1.4.2 SDK 2. Linux RPM ( 9 ) 3. sh j2sdk-1_4_2_07-linux-i586-rpm.bin 4. rpm Uvh j2sdk-1_4_2_07-linux-i586-rpm 5. PATH JAVA 1. vi.bash_profile

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 9 장생성자와접근제어 이번장에서학습할내용 생성자 정적변수 정적메소드 접근제어 this 클래스간의관계 객체가생성될때초기화를담당하는생성자에대하여살펴봅니다. 생성자 생성자 (contructor): 객체가생성될때에필드에게초기값을제공하고필요한초기화절차를실행하는메소드 생성자의예 class Car { private String color; // 색상

More information

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a 6 장복사생성자 객체의생성과대입객체의값에의한전달복사생성자디폴트복사생성자복사생성자의재정의객체의값에의한반환임시객체 C++ 프로그래밍입문 1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y;

More information

Microsoft PowerPoint - Lect04.pptx

Microsoft PowerPoint - Lect04.pptx OBJECT ORIENTED PROGRAMMING Object Oriented Programming 이강의록은 Power Java 저자의강의록을사용했거나재편집된것입니다. Class 와 object Class 와객체 클래스의일생 메소드 필드 String Object Class 와객체 3 클래스 클래스의구성 클래스 (l (class): 객체를만드는설계도 클래스로부터만들어지는각각의객체를특별히그클래스의인스턴스

More information

17장 클래스와 메소드

17장 클래스와 메소드 17 장클래스와메소드 박창이 서울시립대학교통계학과 박창이 ( 서울시립대학교통계학과 ) 17 장클래스와메소드 1 / 18 학습내용 객체지향특징들객체출력 init 메소드 str 메소드연산자재정의타입기반의버전다형성 (polymorphism) 박창이 ( 서울시립대학교통계학과 ) 17 장클래스와메소드 2 / 18 객체지향특징들 객체지향프로그래밍의특징 프로그램은객체와함수정의로구성되며대부분의계산은객체에대한연산으로표현됨객체의정의는

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 11 장상속 1. 상속의개념을이해한다. 2. 상속을이용하여자식클래스를작성할수있다. 3. 상속과접근지정자와의관계를이해한다. 4. 상속시생성자와소멸자가호출되는순서를이해한다. 이번장에서만들어볼프로그램 class Circle { int x, y; int radius;... class Rect { int x, y; int width, height;... 중복 상속의개요

More information

Microsoft Word - java19-1-midterm-answer.doc

Microsoft Word - java19-1-midterm-answer.doc 중간고사 담당교수 : 단국대학교응용컴퓨터공학박경신 답은반드시답안지에기술할것. 공간이부족할경우반드시답안지몇쪽의뒤에있다고명기한후기술할것. 그외의경우의답안지뒤쪽이나연습지에기술한내용은답안으로인정안함. 답에는반드시네모를쳐서확실히표시할것. 답안지에학과, 학번, 이름외에본인의암호 (4자리숫자 ) 를기입하면성적공고시학번대신암호를 사용할것임. 1. 다음질문에답을하라. (55

More information

4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문

4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문 4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문 1. 클래스와객체 추상데이터형 : 속성 (attribute) + 메서드 (method) 예 : 자동차의속성과메서드 C++ : 주로 class

More information

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout <<  양수입력 : ; cin >> *p; if (*p <= 0) cout <<  양수를입력해야합니다  << endl; return; 동적할 15 장기타주제들 auto_ptr 변환함수 cast 연산자에의한명시적형변환실행시간타입정보알아내기 (RTTI) C++ 프로그래밍입문 1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout > *p; if (*p

More information

교육자료

교육자료 THE SYS4U DODUMENT Java Reflection & Introspection 2012.08.21 김진아사원 2012 SYS4U I&C All rights reserved. 목차 I. 개념 1. Reflection 이란? 2. Introspection 이란? 3. Reflection 과 Introspection 의차이점 II. 실제사용예 1. Instance의생성

More information

PowerPoint Template

PowerPoint Template 9. 객체지향프로그래밍 대구가톨릭대학교 IT 공학부 소프트웨어공학연구실 목차 2 9.1 개요 9.2 객체지향프로그래밍언어 9.3 추상자료형 9.4 상속 9.5 동적바인딩 9.1 객체지향의개념 (1) 3 객체지향의등장배경 소프트웨어와하드웨어의발전불균형 소프트웨어모듈의재사용과독립성을강조 객체 (object) 란? 우리가다루는모든사물을일컫는말 예 ) 하나의점, 사각형,

More information

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - C++ 5 .pptx C++ 언어프로그래밍 한밭대학교전자. 제어공학과이승호교수 연산자중복 (operator overloading) 이란? 2 1. 연산자중복이란? 1) 기존에미리정의되어있는연산자 (+, -, /, * 등 ) 들을프로그래머의의도에맞도록새롭게정의하여사용할수있도록지원하는기능 2) 연산자를특정한기능을수행하도록재정의하여사용하면여러가지이점을가질수있음 3) 하나의기능이프로그래머의의도에따라바뀌어동작하는다형성

More information

제1장 자바 언어 소개

제1장 자바 언어 소개 프로그래머를위한 Java 2 제3장객체지향프로그래밍 Software Components 2 Programs are easier to construct and modify they are made up of separate components A software component can be thought of any program element that transforms

More information

슬라이드 1

슬라이드 1 정적메모리할당 (Static memory allocation) 일반적으로프로그램의실행에필요한메모리 ( 변수, 배열, 객체등 ) 는컴파일과정에서결정되고, 실행파일이메모리에로드될때할당되며, 종료후에반환됨 동적메모리할당 (Dynamic memory allocation) 프로그램의실행중에필요한메모리를할당받아사용하고, 사용이끝나면반환함 - 메모리를프로그램이직접관리해야함

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 1,..... @ 1 Green Project 1991 Oak Java 1995. 5 December '90 by Patrick Naughton, Mike Sheridan and James Gosling Embedded in various consumer electronic device 1992. 9. 3 Star 7 1993 www portability

More information

PowerPoint Template

PowerPoint Template 16-1. 보조자료템플릿 (Template) 함수템플릿 클래스템플릿 Jong Hyuk Park 함수템플릿 Jong Hyuk Park 함수템플릿소개 함수템플릿 한번의함수정의로서로다른자료형에대해적용하는함수 예 int abs(int n) return n < 0? -n : n; double abs(double n) 함수 return n < 0? -n : n; //

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 3 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

02 C h a p t e r Java

02 C h a p t e r Java 02 C h a p t e r Java Bioinformatics in J a va,, 2 1,,,, C++, Python, (Java),,, (http://wwwbiojavaorg),, 13, 3D GUI,,, (Java programming language) (Sun Microsystems) 1995 1990 (green project) TV 22 CHAPTER

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 예외처리 (Exception Handling) 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2012-2 nd 프로그래밍입문 (1) 예외상황과예외처리의이해 3 예외상황을처리하지않았을때의결과 예외상황은프로그램실행중에발생하는문제의상황을의미한다. 예외상황의예나이를입력하라고했는데, 0보다작은값이입력됨.

More information

No Slide Title

No Slide Title 예외처리 이충기 명지대학교컴퓨터공학과 예외필요성 오류처리지금까지 : 오류처리를거의하지않았다. 일이의도한대로잘될것이라고가정했다. 주먹구구식방법 : 프로그래머는컴파일오류를찾아서수정하기위해서시험하고오류수정을해야한다. 컴파일러는실행오류의문제를해결하지못한다 ( 예 : 부정확한값이나상태 ). 프로그래머는실행오류가있더라도프로그램이우아하게돌아가야한다는것을보장해야한다. 우아하게

More information

(Microsoft Word - \301\337\260\243\260\355\273\347.docx)

(Microsoft Word - \301\337\260\243\260\355\273\347.docx) 내장형시스템공학 (NH466) 중간고사 학번 : 이름 : 문제 배점 점수 1 20 2 20 3 20 4 20 5 10 6 10 7 15 8 20 9 15 합계 150 1. (20 점 ) 다음용어에대해서설명하시오. (1) 정보은닉 (Information Hiding) (2) 캡슐화 (Encapsulation) (3) 오버로딩 (Overloading) (4) 생성자

More information

Microsoft PowerPoint 장강의노트.ppt

Microsoft PowerPoint 장강의노트.ppt 클래스와객체 클래스와객체 객체 : 우리주변의어떤대상의모델 - 예 : 사람, 차, TV, 개 객체 = 상태 (state) + 행동 (behavior) - 예 : 개의상태 - 종자, 이름, 색개의행동 - 짖다, 가져오다 상태는변수로행동은메소드로나타냄 객체는클래스에의해정의된다. 클래스는객체가생성되는틀혹은청사진이다. 2 예 : 클래스와객체 질문 : 클래스와객체의다른예는?

More information

쉽게

쉽게 Power Java 제 4 장자바프로그래밍기초 이번장에서학습할내용 자바프로그램에대한기초사항을학습 자세한내용들은추후에. Hello.java 프로그램 주석 주석 (comment): 프로그램에대한설명을적어넣은것 3 가지타입의주석 클래스 클래스 (class): 객체를만드는설계도 ( 추후에학습 ) 자바프로그램은클래스들로구성된다. 그림 4-1. 자바프로그램의구조 클래스정의

More information

ThisJava ..

ThisJava .. 자바언어에정확한타입을추가한 ThisJava 소개 나현익, 류석영 프로그래밍언어연구실 KAIST 2014 년 1 월 14 일 나현익, 류석영 자바언어에정확한타입을추가한 ThisJava 소개 1/29 APLAS 2013 나현익, 류석영 자바 언어에 정확한 타입을 추가한 ThisJava 소개 2/29 실제로부딪힌문제 자바스크립트프로그램분석을위한요약도메인 나현익,

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 클래스 배효철 th1g@nate.com 1 목차 객체지향프로그래밍 객체지향프로그래밍의특징 객체와클래스 클래스 클래스의구성 클래스의선언및객체생성 필드 생성자 메소드 2 목차 객체지향프로그래밍 객체지향프로그래밍의특징 객체와클래스 클래스 클래스의구성 클래스의선언및객체생성 필드 생성자 메소드 3 객체지향프로그래밍 객체지향프로그래밍이란? OOP ( Object Oriented

More information

1

1 1 1....6 1.1...6 2. Java Architecture...7 2.1 2SDK(Software Development Kit)...8 2.2 JRE(Java Runtime Environment)...9 2.3 (Java Virtual Machine, JVM)...10 2.4 JVM...11 2.5 (runtime)jvm...12 2.5.1 2.5.2

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 명품 JAVA Essential 1 2 학습목표 1. 객체지향상속과자바상속개념이해 2. 클래스상속작성및객체생성 3. protected 접근지정 4. 상속시생성자의실행과정 5. 업캐스팅과 instanceof 연산자 6. 메소드오버라이딩과동적바인딩의이해및활용 7. 추상클래스 8. 인터페이스 상속 (inheritance) 3 객체지향상속 자식이부모유전자를물려받는것과유사한개념

More information

Microsoft PowerPoint - 04-UDP Programming.ppt

Microsoft PowerPoint - 04-UDP Programming.ppt Chapter 4. UDP Dongwon Jeong djeong@kunsan.ac.kr http://ist.kunsan.ac.kr/ Dept. of Informatics & Statistics 목차 UDP 1 1 UDP 개념 자바 UDP 프로그램작성 클라이언트와서버모두 DatagramSocket 클래스로생성 상호간통신은 DatagramPacket 클래스를이용하여

More information

PowerPoint Template

PowerPoint Template 7. 상속 (inheritance) 의이해 상속의기본개념 상속의생성자, 소멸자 protected 멤버 Jong Hyuk Park 상속의기본개념 Jong Hyuk Park 상속의기본개념 상속의예 1 " 철수는아버지로부터좋은목소리와큰키를물려받았다." 상속의예 2 "Student 클래스가 Person 클래스를상속한다." 아버지 Person 철수 Stduent 3

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스와메소드심층연구 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 접근제어 class A { private int a; int b; public int c; // 전용 // 디폴트 // 공용 public class Test { public static void main(string args[]) { A obj = new

More information

rmi_박준용_final.PDF

rmi_박준용_final.PDF (RMI) - JSTORM http://wwwjstormpekr (RMI)- Document title: Document file name: Revision number: Issued by: Document Information (RMI)- rmi finaldoc Issue Date: Status:

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 9 강. 클래스의활용목차 멤버함수의외부정의 this 포인터 friend 선언 static 멤버 임시객체 1 /17 9 강. 클래스의활용멤버함수의외부정의 멤버함수정의구현방법 내부정의 : 클래스선언내에함수정의구현 외부정의 클래스선언 : 함수프로토타입 멤버함수정의 : 클래스선언외부에구현

More information

Microsoft Word - EEL2 Lab4.docx

Microsoft Word - EEL2 Lab4.docx EEL2 LAB Week 4: Inheritance 1. 다음을만족하는클래스 Employee를작성하시오.(1에서 4번까지관련된문제입니다.) 클래스 Employee 직원는클래스 Regular 정규직와 Temporary 비정규직의상위클래스 필드 : 이름, 나이, 주소, 부서, 월급정보를필드로선언 생성자 : 이름, 나이, 주소, 부서를지정하는생성자정의 메소드 printinfo():

More information

Microsoft PowerPoint - ch07 - 포인터 pm0415

Microsoft PowerPoint - ch07 - 포인터 pm0415 2015-1 프로그래밍언어 7. 포인터 (Pointer), 동적메모리할당 2015 년 4 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) Outline 포인터 (pointer) 란? 간접참조연산자

More information

슬라이드 1

슬라이드 1 9 장. 생성자와가비지컬렉션 학습목표 스택과힙지역변수와인스턴스변수객체생성과생성자객체제거 ( 가비지컬렉션 ) 객체의삶과죽음 그리고그가말했어. 다리에감각이없어! 그리고내가말했지. 조! 정신차려조! 하지만이미너무늦었어. 가비지컬렉터가나타났고그는죽고말았지. 내가만나본가장좋은객체였는데말야 스택과힙 스택 (stack) 메소드호출과지역변수가사는곳 지역변수는스택변수라고도부릅니다.

More information

int total = 0; for( int i=1; i<=5; i++ ) { for( int j=1; j<=i; i++ ) { total ++; System.out.println( total ); 대구분 : 객체와 Class 소구분 : 객체생성과사용 / Class 선언

int total = 0; for( int i=1; i<=5; i++ ) { for( int j=1; j<=i; i++ ) { total ++; System.out.println( total ); 대구분 : 객체와 Class 소구분 : 객체생성과사용 / Class 선언 과목명총문항수 O/X 문제형 4 지선다형 5 지선다형단답형서술형 JAVA( 필기테스트 ) 20 문항 0 문항 10 문항 0 문항 10 문항 0 문항 대구분 : Java API 소구분 : Object class/string class/stringbuffer/wrapper ( 단답형 ) [Q1] 다음프로그램은간단한회원정보를포함하고있는클래스를작성한것이다. 실행결과를적으시오.

More information

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Function) 1. 함수의개념 입력에대해적절한출력을발생시켜주는것 내가 ( 프로그래머 ) 작성한명령문을연산, 처리, 실행해주는부분 ( 모듈 ) 자체적으로실행되지않으며,

More information