Microsoft PowerPoint - java1-lecture5.ppt [호환 모드]

Size: px
Start display at page:

Download "Microsoft PowerPoint - java1-lecture5.ppt [호환 모드]"

Transcription

1 Private Constructor 객체지향개념상속, 추상클래스, 다형성 년가을학기 9/25/2017 박경신 Private 생성자 정적멤버만포함하는클래스에서일반적으로사용 클래스가인스턴스화될수없음을분명히하기위해 private constructor를사용 public class Counter { private Counter() { public static int currentcount; public static int IncrementCount() { return ++currentcount; class TestCounter { //Counter acounter = new Counter(); // Error Counter.currentCount = 100; Counter.IncrementCount(); System.out.println( count= +Counter.currentCount); Protected Constructor Protected 생성자 Protected 생성자는추상클래스 (abstract class) 에서사용을권함. 추상클래스에는 protected 또는 default 생성자를정의함. 추상클래스를상속받은파생클래스에서추상클래스의 protected 생성자를호출하여초기화작업을수행함. abstract class Shape { protected Shape(String name) { this.name = name; private String name; public void print() { System.out.println(this.name); class Triangle extends Shape { public Triangle(string name) { super(name); class Rectangle extends Shape { public Rectangle(string name) { super(name); public class ShapeTest { //Shape s= new Shape( 도형 ); // error Shape is abstract: cannot be instantiated Shape s = new Triangle( 삼각형 ); s.print(); // 삼각형 s = new Rectangle( 직사각형 ); s.print(); // 직사각형 Static vs Instance Initializer Block Static Initializer Block 클래스로딩시호출 instance 필드메소드사용못함 static 변수초기화에사용 Instance Initializer Block 객체생성시호출 super 생성자이후에실행하고생성자보다먼저실행 instance 필드메소드에접근가능 모든생성자의공통부분을 instance initializer block 에넣어줌 class StaticPoint { private static int[] data ; static { data = new int[] { 1, 2, 3 ; class InstancePoint { private int[] data ; { data = new int[] { 100, 200 ; public InstancePoint() { System.out.println( 기본생성자 ); public InstancePoint(int x) { System.out.println( 생성자 );

2 Instance vs Static Field Instance field 객체의현재상태를저장할수있는자료 객체생성시메모리공간할당 Static(Class) field 전역데이터, 공유데이터로클래스로드시공간을할당함 클래스당하나만정적필드가할당 객체의개수를카운트하거나통계값들을저장하는경우사용함 Withdraw( ) Deposit( ) balance 1000 interest 7% Withdraw( ) Deposit( ) balance interest 7% Instance vs Static Method Instance method 객체생성시메모리공간할당 정적멤버 (static field & method) 도사용가능 Static(Class) method 클래스로딩시할당, 객체생성없이정적메소드실행가능 정적멤버 (static field & method) 를접근할수있는메소드 인스턴스멤버 (instance field & method) 사용불가 this 사용불가 BankAccount Instance BankAccount Class InterestRate( ) interest 7% Withdraw( ) Deposit( ) balance 상속 (Inheritance) 상속관계예 상속 상위클래스의특성 ( 필드, 메소드 ) 을하위클래스에물려주는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정 구체적으로오버라이딩이라고부름 슈퍼클래스에서하위클래스로갈수록구체적 예 ) 폰 -> 모바일폰 -> 뮤직폰 상속을통해간결한서브클래스작성 동일한특성을재정의할필요가없어서브클래스가간결해짐 class Phone class MobilePhone class MusicMobilePhone 전화걸기전화받기 상속 무선기지국연결배터리충전하기 상속 음악다운받기음악재생하기 구체화

3 상속의필요성 클래스상속과객체 상속이없는경우중복된멤버를가진 4 개의클래스 상속을이용한경우중복이제거되고간결해진클래스구조 상속선언 public class Person {... public class Student extends Person { // Person 을상속받는클래스 Student 선언... public class StudentWorker extends Student { // Student 를상속받는 StudentWorker 선언... 자바상속의특징 클래스다중상속지원하지않음 다수개의클래스를상속받지못함 상속횟수무제한 상속의최상위클래스는 java.lang.object 클래스 모든클래스는자동으로 java.lang.object 를상속받음 예제 : Point & ColorPoint 클래스 (x,y) 의한점을표현하는 Point 클래스와이를상속받아컬러점을표현하는 ColorPoint 클래스를만들어보자. public class Point { private int x, y; // 한점을구성하는 x, y 좌표 public void set(int x, int y) { this.x = x; this.y = y; public int getx() { return x; public int gety() { return y; public void showpoint() { // 점의좌표출력 System.out.println("(" + x + "," + y + ")"); 예제 : Point & ColorPoint 클래스 public class ColorPoint extends Point { // Point 를상속받은 ColorPoint 선언 String color; // 점의색 void setcolor(string color) { this.color = color; void showcolorpoint() { // 컬러점의좌표출력 System.out.print(color); showpoint(); // Point 클래스의 showpoint() 호출 public static void main(string [] args) { ColorPoint cp = new ColorPoint(); cp.set(3,4); // Point 클래스의 set() 메소드호출 cp.setcolor("red"); // 색지정 cp.showcolorpoint(); // 컬러점의좌표출력 red(3,4) 12

4 예제 : Shape & Rectangle 클래스 예제 : Shape & Rectangle 클래스 public class Shape { private int x; private int y; public int getx() { return x; public int gety() { return y; void set(int x, int y) { this.x = x; this.y = y; void print() { // x,y 좌표출력 System.out.println("(" + x + "," + y + ")"); public class Rectangle extends Shape { private int width; // 사각형의너비 private int height; // 사각형의높이 public void getwidth() { return width; public void getheight() { return height; public void setwidth(int width) { this.width = width; public void setheight(int height) { this.height = height; public double area() { // 사각형의넓이 ( 영역 ) return (double)width * height); void draw() { // x, y 출력 System.out.println( 사각형 " + getx()+ x" + gety() + " 의영역은 + area()); public class RectangleTest { public static void main(string [] args) { Rectangle r1 = new Rectangle(); Rectangle r2 = new Rectangle(); r1.set(5,3); // Shape 클래스의 set() 메소드호출 r1.setwidth(10); // Rectangle 클래스의 setwidth() 메소드호출 r1.setheight(20); // Rectangle 클래스의 setheight() 메소드호출 r2.set(8,9); // Shape 클래스의 set() 메소드호출 r2.setwidth(10); // Rectangle 클래스의 setwidth() 메소드호출 r2.setheight(20); // Rectangle 클래스의 setheight() 메소드호출 r1.print(); // x,y 좌표출력 r1.draw(); // x,y,width,height,area 출력 r2.print(); // x,y 좌표출력 r2.draw(); // x,y,width,height,area 출력 서브클래스의객체와멤버사용 슈퍼클래스와서브클래스의객체관계 서브클래스의객체와멤버접근 서브클래스의객체에는슈퍼클래스멤버포함 슈퍼클래스의 private 멤버는상속되지만서브클래스에서직접접근불가 슈퍼클래스의 private 멤버는슈퍼클래스의 public/protected 메소드를통해접근 16

5 서브클래스의객체멤버접근 상속과접근지정자 자바의접근지정자 4 가지 public, protected, default, private 상속관계에서주의할접근지정자는 private 와 protected 슈퍼클래스의 private 멤버 슈퍼클래스의 private 멤버는다른모든클래스에접근불허 슈퍼클래스의 protected 멤버 같은패키지내의모든클래스접근허용 동일패키지여부와상관없이서브클래스에서슈퍼클래스의 protected 멤버접근가능 슈퍼클래스멤버의접근지정자 슈퍼클래스와서브클래스가같은패키지 ( 같은폴더, 디렉토리 ) 에있는경우

6 슈퍼클래스와서브클래스가서로다른패키지 ( 다른폴더, 디렉토리 ) 에있는경우 예제 : 상속관계에있는클래스간멤버접근 Person 클래스는아래와같은멤버필드를갖도록선언한다. int age; public String name; protected int height; private int weight; Student 클래스는 Person 클래스를상속받아각멤버필드에값을저장한다. Person 클래스의 private 필드인 weight는 Student 클래스에서는접근이불가능하여슈퍼클래스인 Person의 get, set 메소드를통해서만조작이가능하다. class Person { int age; public String name; protected int height; private int weight; public void setweight(int weight) { this.weight = weight; 21 public int getweight() { return weight; 예제 : 상속관계에있는클래스간멤버접근 public class Student extends Person { void set() { age = 30; name = " 홍길동 "; height = 175; setweight(99); 서브클래스 / 슈퍼클래스의생성자호출과실행 new에의해서브클래스의객체가생성될때 슈퍼클래스생성자와서브클래스생성자모두실행됨 호출순서 서브클래스의생성자가먼저호출, 서브클래스의생성자는실행전슈퍼클래스생성자호출 실행순서 슈퍼클래스의생성자가먼저실행된후서브클래스의생성자실행 Student s = new Student(); s.set();

7 슈퍼클래스와서브클래스의생성자간의호출및실행관계 생성자 A 생성자 B 생성자 C 서브클래스와슈퍼클래스의생성자짝맞추기 슈퍼클래스와서브클래스 각각여러개의생성자작성가능 슈퍼클래스와서브클래스의생성자사이의짝맞추기 서브클래스와슈퍼클래스의생성자조합 4 가지 서브클래스에서슈퍼클래스의생성자를선택하지않는경우 컴파일러가자동으로슈퍼클래스의기본생성자선택 서브클래스개발자가슈퍼클래스의생성자를명시적으로선택하는경우 super() 키워드를이용하여선택 슈퍼클래스의기본생성자자동호출 서브클래스의기본생성자경우 슈퍼클래스에기본생성자가없어오류난경우 서브클래스의생성자가슈퍼클래스의생성자를선택하지않은경우 서브클래스의생성자가기본생성자인경우, 컴파일러는자동으로슈퍼클래스의기본생성자와짝을맺음 컴파일러가 public B() 에대한짝을찾을수없음 생성자 A 생성자 B 컴파일러에의해 Implicit super constructor 28 A() is undefined. Must explicitly invoke another constructor 오류발생

8 슈퍼클래스의기본생성자자동호출 서브클래스의매개변수를가진생성자경우 서브클래스의생성자가슈퍼클래스의생성자를선택하지않은경우 super() 를이용하여슈퍼클래스생성자선택 super() 서브클래스에서명시적으로슈퍼클래스의생성자를선택호출할때사용 사용방식 super(parameter); 인자를이용하여슈퍼클래스의적당한생성자호출 반드시서브클래스생성자코드의제일첫라인에와야함 생성자 A 매개변수생성자 B super() 를이용한사례 객체의타입변환 업캐스팅 (upcasting) 프로그램에서이루어지는자동타입변환 서브클래스의레퍼런스값을슈퍼클래스레퍼런스에대입 슈퍼클래스레퍼런스가서브클래스객체를가리키게되는현상 객체내에있는모든멤버를접근할수없고슈퍼클래스의멤버만접근가능 super(); 라고하면 A() 호출 class Person { class Student extends Person {... 매개변수생성자 A5 매개변수생성자 B5 31 Student s = new Student(); Person p = s; // 업캐스팅, 자동타입변환

9 업캐스팅사례 class Person { String name; String id; public Person(String name) { this.name = name; class Student extends Person { String grade; String department; public Student(String name) { super(name); public class UpcastingEx { Person p; Student s = new Student( 이재문 ); p = s; // 업캐스팅발생 System.out.println(p.name); // 오류없음 //p.grade = "A"; // 컴파일오류 //p.department = "Com"; // 컴파일오류 이재문 객체의타입변환 다운캐스팅 (downcasting) 슈퍼클래스레퍼런스를서브클래스레퍼런스에대입 업캐스팅된것을다시원래대로되돌리는것 명시적으로타입지정 class Person { class Student extends Person {... Student s = (Student)p; // 다운캐스팅, 강제타입변환 다운캐스팅사례 instanceof 연산자와객체의타입구별 업캐스팅된레퍼런스로는객체의진짜타입을구분하기어려움 슈퍼클래스는여러서브클래스에상속되기때문 슈퍼클래스레퍼런스로서브클래스객체를가리킬수있음 instanceof 연산자 instanceof 연산자 레퍼런스가가리키는객체의진짜타입식별 사용법 객체레퍼런스 instanceof 클래스타입 연산의결과 : true/false 의불린값

10 업캐스팅된객체의실제타입은무엇? instanceof 사용예 예제 : instanceof 를이용한객체구별 instanceof 를이용하여객체의타입을구별하는예를만들어보자 jee 는 Student 타입 kim 은 Professor 타입 kim 은 Researcher 타입 kim 은 Person 타입 "java" 는 String 타입 class Person { class Student extends Person { class Researcher extends Person { class Professor extends Researcher { public class InstanceofExample { Person jee= new Student(); Person kim = new Professor(); Person lee = new Researcher(); if (jee instanceof Student) // jee는 Student 타입이므로 true System.out.println("jee는 Student 타입 "); if ( jee instanceof Researcher) // jee는 Researcher 타입이아니므로 false System.out.println("jee는 Researcher 타입 "); if (kim instanceof Student) // kim은 Student 타입이아니므로 false System.out.println("kim은 Student 타입 "); if (kim instanceof Professor) // kim은 Professor 타입이므로 true System.out.println("kim은 Professor 타입 "); if (kim instanceof Researcher) // kim은 Researcher 타입이기도하므로 true System.out.println("kim은 Researcher 타입 "); if (kim instanceof Person) // kim은 Person 타입이기도하므로 true System.out.println("kim은 Person 타입 "); if (lee instanceof Professor) // lee는 Professor 타입이아니므로 false System.out.println("lee는 Professor 타입 "); if ("java" instanceof String) // "java" 는 String 타입의인스턴스이므로 true System.out.println("\"java\" 는39String 타입 "); Method Overriding class Animal { public void sound() { ; class Dog extends Animal { public void sound() { System.out.println(" 멍멍!"); ; public class DogTest { Dog d = new Dog(); d.sound(); ; Animal 1부터멍멍! 10까지의정수의합 = 55

11 Method Overriding Method Overriding 사례 메소드오버라이딩 (Method Overriding) 슈퍼클래스의메소드를서브클래스에서재정의 슈퍼클래스의메소드이름, 메소드인자타입및개수, 리턴타입등모든것동일하게작성 이중하나라도다르면메소드오버라이딩실패 동적바인딩발생 서브클래스에오버라이딩된메소드가무조건실행되도록동적바인딩됨 동적바인딩발생 메소드 2() 오버라이딩 서브클래스객체와오버라이딩된메소드호출 예제 : void draw() 메소드오버라이딩예 class DObject { public DObject next; public DObject() { next = null; System.out.println("DObject draw"); class Line extends DObject { // 메소드오버라이딩 System.out.println("Line"); class Rect extends DObject { // 메소드오버라이딩 System.out.println("Rect"); class Circle extends DObject { // 메소드오버라이딩 System.out.println("Circle"); public class MethodOverringEx { DObject obj = new DObject(); Line line = new Line(); DObject p = new Line(); DObject r = line; obj.draw(); // DObject.draw() 실행. "DObject draw" 출력 line.draw(); // Line.draw() 실행. "Line" 출력 p.draw(); // 오버라이딩된 Line.draw() 실행, "Line" 출력 r.draw(); // 오버라이딩된 Line.draw() 실행, "Line" 출력 DObject rect = new Rect(); DObject circle = new Circle(); rect.draw(); // 오버라이딩된 Rect.draw() 실행, "Rect" 출력 circle.draw(); // 오버라이딩된 Circle.draw() 실행, "Circle" 출력 DObject draw Line Line Line Rect Circle

12 예제실행과정 45 메소드오버라이딩조건 1. 반드시슈퍼클래스메소드와동일한이름, 동일한호출인자, 반환타입을가져야한다. 2. 오버라이딩된메소드의접근지정자는슈퍼클래스의메소드의접근지정자보다좁아질수없다. public > protected > private 순으로지정범위가좁아진다. 3. 반환타입만다르면오류 4. private, final 메소드는오버라이딩될수없다. class Person { String name; String phone; private int ID; public void setname(string s) { name = s; public String getphone() { return phone; public final int getid() { return ID; class Professor extends Person { //protected void setname(string s) { // public 을 protected 로지정할수없음 // // 동일한메소드명, 인자, 반환타입을가짐 public String getphone() { return phone; //public void getphone(){ // 반환타입다르면오류 // //public int getid() { // final 은 override 할수없음 // return ID // Person 의 ID 는 private 이라서오류 // 오버라이딩활용 public static void main(string [] args) { DObject start, n, obj; // 링크드리스트로도형생성하여연결하기 start = new Line(); //Line 객체연결 n = start; obj = new Rect(); n.next = obj; //Rect 객체연결 n = obj; obj = new Line(); // Line 객체연결 n.next = obj; n = obj; obj = new Circle(); // Circle 객체연결 n.next = obj; // 모든도형출력하기 while(start!= null) { start.draw(); start = start.next; Line Rect Line Circle 동적바인딩 오버라이딩메소드가항상호출된다. public class SuperObject { protected String name; public void paint() { draw(); System.out.println("Super Object"); public static void main(string [] args) { SuperObject a = new SuperObject(); a.paint(); class SuperObject { protected String name; public void paint() { draw(); 동적바인딩 System.out.println("Super Object"); public class SubObject extends SuperObject { System.out.println("Sub Object"); public static void main(string [] args) { SuperObject b = new SubObject(); b.paint(); Super Object Sub Object 47

13 super 키워드 super 키워드 super 는슈퍼클래스의멤버를접근할때사용되는레퍼런스 서브클래스에서만사용 슈퍼클래스의메소드호출시사용 컴파일러는 super 호출을정적바인딩으로처리 class SuperObject { protected String name; public void paint() { draw(); System.out.println(name); public class SubObject extends SuperObject { protected String name; name = "Sub"; super.name = "Super"; super.draw(); System.out.println(name); public static void main(string [] args) { SuperObject b = new SubObject(); b.paint(); Super Sub 예제 : Method Overriding Person 을상속받는 Professor 라는새로운클래스를만들고 Professor 클래스에서 getphone() 메소드를재정의하라. 그리고이메소드에서슈퍼클래스의메소드를호출하도록작성하라. class Person { String phone; public void setphone(string phone) { this.phone = phone; super.getphone() 은 public String getphone() { 아래 p.getphone() 과 return phone; 달리동적바인딩이 일어나지않는다. class Professor extends Person { public String getphone() { return "Professor : " + super.getphone(); public class Overriding { Professor a = new Professor(); a.setphone(" "); System.out.println(a.getPhone()); Person p = a; System.out.println(p.getPhone()); Professor : Professor : 동적바인딩에의해 Professor 의 getphone() 호출. Method Overloading vs Overriding 추상메소드와추상클래스 추상메소드 (abstract method) 선언되어있으나구현되어있지않은메소드 abstract 키워드로선언 ex) public abstract int getvalue(); 추상메소드는서브클래스에서오버라이딩하여구현 추상클래스 (abstract class) 1. 추상메소드를하나라도가진클래스 클래스앞에반드시 abstract라고선언해야함 2. 추상메소드가하나도없지만클래스앞에 abstract로선언한경우 추상클래스 추상메소드 abstract class DObject { public DObject next; public DObject() { next = null; abstract public void draw() ;

14 2 가지종류의추상클래스사례 추상클래스의인스턴스생성불가 // 추상메소드를가진추상클래스 abstract class DObject { // 추상클래스선언 public DObject next; public DObject() { next = null; abstract public void draw(); // 추상메소드선언 // 추상메소드없는추상클래스 abstract class Person { // 추상클래스선언 public String name; public Person(String name) { this.name = name; public String getname() { return name; abstract class DObject { // 추상클래스선언 public DObject next; public DObject() { next = null; abstract public void draw(); // 추상메소드선언 public class AbstractError { public static void main(string [] args) { DObject obj; obj = new DObject(); // 컴파일오류, 추상클래스 DObject 의인스턴스를생성할수없다. obj.draw(); // 컴파일오류 추상클래스의상속 추상클래스의상속 2 가지경우 추상클래스의단순상속 추상클래스를상속받아, 추상메소드를구현하지않으면서브클래스도추상클래스됨 서브클래스도 abstract로선언해야함 abstract class DObject { // 추상클래스 public DObject next; public DObject() { next = null; abstract public void draw(); // 추상메소드 abstract class Line extends DObject { // draw() 를구현하지않았기때문에추상클래스 public String tostring() { return "Line"; 추상클래스구현상속 서브클래스에서슈퍼클래스의추상메소드구현 ( 오버라이딩 ) 서브클래스는추상클래스아님 추상클래스의구현및활용예 class Line extends DObject { System.out.println( Line ); 추상클래스를상속받아추상메소드 draw() 를구현한클래스 abstract class DObject { public DObject next; public DObject() { next = null; abstract public void draw(); class Rect extends DObject { System.out.println( Rect ); class DObject { public DObject next; public DObject() { next = null; System.out.println( DObject draw ); 추상클래스로수정 class Circle extends DObject { System.out.println( Circle );

15 추상클래스의용도 설계와구현분리 서브클래스마다목적에맞게추상메소드를다르게구현 다형성실현 슈퍼클래스에서는개념정의 서브클래스마다다른구현이필요한메소드는추상메소드로선언 각서브클래스에서구체적행위구현 계층적상속관계를갖는클래스구조를만들때 예제 : Calculator 추상클래스 다음의추상클래스 Calculator 를상속받는 GoodCalc 클래스를작성하라. abstract class Calculator { public abstract int add(int a, int b); public abstract int subtract(int a, int b); public abstract double average(int[] a); 예제 : GoodCalc 클래스 다형성 (Polymorphism) class GoodCalc extends Calculator { public int add(int a, int b) { return a+b; public int subtract(int a, int b) { return a - b; public double average(int[] a) { double sum = 0; for (int i = 0; i < a.length; i++) sum += a[i]; return sum/a.length; public static void main(string [] args) { Calculator c = new GoodCalc(); System.out.println(c.add(2,3)); System.out.println(c.subtract(2,3)); System.out.println(c.average(new int [] {2,3,4)); 다형성 (polymorphism) 이란객체들의타입이다르면똑같은메시지가전달되더라도각객체의타입에따라서서로다른동작을하는것 (dynamic binding)

16 예제 : 다형성예시 class Shape { protected int x, y; System.out.println("Shape Draw"); class Rectangle extends Shape { private int width, height; System.out.println("Rectangle Draw"); class Triangle extends Shape { private int base, height; System.out.println("Triangle Draw"); 예시 : 다형성예시 class Circle extends Shape { private int radius; System.out.println("Circle Draw"); public class ShapeTest { public static void main(string arg[]) { Shape s1 = new Shape(); Shape s2 = new Rectangle(); Shape s3 = new Triangle(); Shape s4 = new Circle(); s1.draw(); Shape Draw s2.draw(); Rectangle Draw s3.draw(); Triangle Draw s4.draw(); Circle Draw 예시 : 다형성예시 public class ShapeTest2 { private static Shape arrayofshapes[]; public static void main(string arg[]) { arrayofshapes = new Shape[3]; arrayofshapes[0] = new Shape(); arrayofshapes[1] = new Rectangle(); arrayofshapes[2] = new Triangle(); arrayofshapes[3] = new Circle(); 자바의클래스계층구조 자바에서는모든클래스는반드시 java.lang.object 클래스를자동으로상속받는다. // 실행시객체의타입에맞는메소드를호출하는동적바인딩 (dynamic binding) for (int i = 0; i < arrayofshapes.length; i++) { arrayofshapes[i].draw(); Shape Draw Rectangle Draw Triangle Draw Circle Draw

17 Object 의메소드 Object 의메소드 class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public class ObjectProperty { public static void main(string [] args) { Point p = new Point(2,3); System.out.println(p.getClass().getName()); System.out.println(p.hashCode()); System.out.println(p.toString()); System.out.println(p); Point Point@c17164 Point@c17164 instanceof getclass() 메소드 객체의실제타입인지여부를반환한다. Shape s = getshape(); if (s instanceof Rectangle) { System.out.println("Rectangle 이생성되었습니다 "); else { System.out.println("Rectangle 이아닌다른객체가생성되었습니다 "); class Car {... public class CarTest { Car obj = new Car(); System.out.println("obj is of type " + obj.getclass().getname()); obj is of type Car obj is of type Car

18 equals() 메소드 class Car { private String model; public Car(String model) { this.model= model; public boolean equals(object obj) { if (obj instanceof Car) return model.equals(((car) obj).model); else return false; public class CarTest { Car firstcar = new Car("HMW520"); Car secondcar = new Car("HMW520"); Object 의 equals() 를재정의 if (firstcar.equals(secondcar)) { System.out.println(" 동일한종류의자동차입니다."); else { System.out.println(" 동일한종류의자동차가아닙니다."); 동일한 1부터 10종류의까지의자동차입니다정수의합 = 55. 객체비교 (== 과 equals()) 객체레퍼런스의동일성비교엔 == 연산자이용 객체내용비교 서로다른두객체가같은내용물인지비교 boolean equals(object obj) 이용 class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; c a b x=2 y=3 x=2 y=3 Point Point Point a = new Point(2,3); Point b = new Point(2,3); Point c = a; if(a == b) // false System.out.println("a==b"); if(a == c) // true System.out.println("a==c"); a==c 객체비교 (== 과 equals()) class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public boolean equals(point p) { if(x == p.x && y == p.y) return true; else return false; a is equal to b Point a = new Point(2,3); Point b = new Point(2,3); Point c = new Point(3,4); if(a == b) // false System.out.println("a==b"); if(a.equals(b)) // true System.out.println("a is equal to b"); if(a.equals(c)) // false System.out.println("a is equal to c"); a b c x=2 y=3 x=2 y=3 x=3 y=4 Point Point Point 예시 : Rect 클래스 equals() int 타입의 width, height 의필드를가지는 Rect 클래스를작성하고, 두 Rect 객체의 width, height 필드에의해구성되는면적이같으면두객체가같은것으로판별하도록 equals() 를작성하라. Rect 생성자에서 width, height 필드를인자로받아초기화한다. class Rect { int width; int height; public Rect(int width, int height) { this.width = width; this.height = height; public boolean equals(rect p) { if (width*height == p.width*p.height) return true; else return false;

19 예시 : Rect 클래스 equals() public class EqualsEx { Rect a = new Rect(2,3); Rect b = new Rect(3,2); Rect c = new Rect(3,4); if(a.equals(b)) System.out.println("a is equal to b"); if(a.equals(c)) System.out.println("a is equal to c"); if(b.equals(c)) System.out.println("b is equal to c"); hashcode() 메소드 hashcode() 는해싱이라는탐색알고리즘에서필요한해시값을생성하는메소드이다. a is equal to b tostring() 메소드 Object 클래스의 tostring() 메소드는객체의문자열표현을반환한다. class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public String tostring() { return "Point(" + x + "," + y+ ")"; public class ObjectProperty { public static void main(string [] args) { Point a = new Point(2,3); System.out.println(a.toString()); Point(2,3) Object 의 tostring() 를재정의 System.out.println(a); 라고해도동일 tostring() 메소드사용 String tostring() 객체를문자열로반환 Object 클래스에구현된 tostring() 이반환하는문자열 객체의 hash code 각클래스는 tostring() 을오버라이딩하여자신만의문자열리턴가능 컴파일러에의한자동변환 객체 + 문자열 -> 객체.toString() + 문자열 로자동변환 Point a = new Point(2,3); String s = a + " 점 "; System.out.println(s); 변환 Point a = new Point(2,3); String s = a.tostring()+ " 점 "; System.out.println(s.toString()); Point@c17164 점

20 IS-A 관계 is-a 관계 : ~ 은 ~ 이다 와같은관계 상속은 is-a 관계이다. HAS-A 관계 has-a 관계 : ~ 은 ~ 을가지고있다 와같은관계 자동차는탈것이다 (Car is a Vehicle). 강아지는동물이다 (Dog is a animal). 도서관은책을가지고있다 (Library has a book). 거실은소파를가지고있다 (Living room has a sofa). HAS-A 관계 HAS-A 관계의예제 객체지향프로그래밍에서 has-a 관계는구성관계 (composition) 또는집합관계 (aggregation) 를나타낸다.

21 예시 : Date 클래스 public class Date { private int year; private int month; private int date; public Date(int year, int month, int date) { this.year = year; this.month = month; this.date = public String tostring() { return "Date [year=" + year + ", month=" + month + ", date=" + date + "]"; 예시 : Employee 클래스 has-a Date 클래스 public class Employee { private String name; private Date birthdate; public Employee(String name, Date birthdate) { this.name = name; this.birthdate = public String tostring() { return "Employee [name=" + name + ", birthdate=" + birthdate + "]"; 예시 : Employee 클래스 has-a Date 클래스 public class EmployeeTest { Date birth = new Date(1990, 1, 1); Employee employee = new Employee(" 홍길동 ", birth); System.out.println(employee); Employee [name= 홍길동, birthdate=date [year=1990, month=1, date=1]] 정적메소드오버라이딩 부모클래스의메소드중에서정적메소드를재정의 ( 오버라이드 ) 하면부모클래스객체에서호출되느냐아니면자식클래스에서호출되느냐에따라서호출되는메소드가달라진다. public class Animal { public static void eat() { System.out.println("Animal의정적메소드 eat()"); public void sound() { System.out.println("Animal의인스턴스메소드 sound()");

22 정적메소드오버라이딩 public class Cat extends Animal { public static void eat() { System.out.println("Cat의정적메소드 eat()"); public void sound() { System.out.println("Cat의인스턴스메소드 sound()"); Cat mycat = new Cat(); Cat.eat(); Animal myanimal = mycat; Animal.eat(); Cat의정적메소드 eat() myanimal.sound(); Animal의정적메소드 eat() Cat의인스턴스메소드 sound()

Microsoft PowerPoint - java1-lecture5.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture5.ppt [호환 모드] 상속 (Inheritance) 객체지향개념상속, 추상클래스, 다형성 514760-1 2016 년가을학기 10/06/2016 박경신 상속 상위클래스의특성 ( 필드, 메소드 ) 을하위클래스에물려주는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성

More information

JAVA PROGRAMMING 실습 07. 상속

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

More information

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D35C0E5BBF3BCD3B0FAB4D9C7FCBCBA>

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D35C0E5BBF3BCD3B0FAB4D9C7FCBCBA> 명품 JAVA Programming 1 제 5 장상속과다형성 상속 (inheritance) 2 상속 상위클래스의특성 ( 필드, 메소드 ) 을하위클래스에물려주는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정

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

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

PowerPoint Presentation

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

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

PowerPoint 프레젠테이션

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

More information

Microsoft PowerPoint - 5장

Microsoft PowerPoint - 5장 1 (inheritance) 2 제 5 장과다형성 상위클래스의특성 ( 필드, 메소드 ) 을하위클래스에물려주는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정 : 구체적으로오버라이딩이라고부름 슈퍼클래스에서하위클래스로갈수록구체적

More information

쉽게 풀어쓴 C 프로그래밍

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

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

PowerPoint 프레젠테이션

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

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

쉽게 풀어쓴 C 프로그래밍

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

More information

PowerPoint 프레젠테이션

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

More information

Microsoft PowerPoint - 2강

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

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

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 예제 1. 필드만있는클래스 텔레비젼 2 예제 1. 필드만있는클래스 3 예제 2. 여러개의객체생성하기 4 5 예제 3. 메소드가추가된클래스 public class Television { int channel; // 채널번호 int volume; // 볼륨 boolean

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

Microsoft PowerPoint - 6주차.pptx

Microsoft PowerPoint - 6주차.pptx 1 6 주차 클래스상속 유전적상속과객체지향상속 2 그래요우리를꼭닮았어요 아빠의유산이다. 나를꼭닮았군 유산상속 유전적상속 : 객체지향상속 생물 동물 식물 상속받음 어류사람나무풀 유전적상속과관계된생물분류 C++ 에서의상속 (Inheritance) 3 C++ 에서의상속이란? 클래스사이에서상속관계정의 객체사이에는상속관계없음 기본클래스의속성과기능을파생클래스에물려주는것

More information

JAVA PROGRAMMING 실습 02. 표준 입출력

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

More information

PowerPoint 프레젠테이션

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

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

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

쉽게 풀어쓴 C 프로그래밍

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

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 자바프로그래밍 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

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

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

More information

C++ Programming

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

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 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

No Slide Title

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

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

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public Chapter 9 Lab 문제정답 1. public class Circle private double radius; static final double PI=3.141592; // PI 이름으로 3.141592 로초기화된정적상수 (1) public Circle(double r) radius = r; (2) public double getradius() return

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

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

슬라이드 1

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

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 2015 학년도 2 학기 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

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

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 클래스 ( 계속 ) 배효철 th1g@nate.com 1 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 2 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 3 인스턴스멤버와 this 인스턴스멤버란?

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

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

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 클래스 ( 계속 ) 배효철 th1g@nate.com 1 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 2 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 3 인스턴스멤버와 this 인스턴스멤버란?

More information

Microsoft PowerPoint - chap11

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

More information

쉽게 풀어쓴 C 프로그래밍

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

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

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074> 객체지향프로그램밍 (Object-Oriented Programming) 1 C++ popular C 객체지향 (object oriented) C++ C : 상위계층언어특징 + 어셈블리언어특징 C++ : 소프트웨어개발플랫폼에객체지향개념제공 객체지향 : 자료와이들자료를어떻게다룰것인지따로생각하지않고단지하나의사물로생각 형 변수가사용하는메모리크기 변수가가질수있는정보

More information

PowerPoint Presentation

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

More information

Microsoft PowerPoint - java2 [호환 모드]

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

More information

Chapter 6 Objects and Classes

Chapter 6 Objects and Classes 11 장상속과다형성 1 강의목표 상속 (inheritance) 을이용하여기본클래스 (base class) 로부터파생클래스 (derived class) 생성 (11.2) 파생클래스유형의객체를기본클래스유형의매개변수 (parameter) 로전달함으로써일반화프로그래밍 (generic programming) 작업 (11.3) 생성자와소멸자의연쇄적처리 (chaining)

More information

설계란 무엇인가?

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

More information

쉽게 풀어쓴 C 프로그래밍

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

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스와메소드심층연구 손시운 ssw5176@kangwon.ac.kr 접근제어 클래스안에변수나메소드들을누구나사용할수있게하면어떻게될까? 많은문제가발생할것이다. ( 예 ) 국가기밀서류를누구나보도록방치하면어떻게될까? 2 접근제어 접근제어 (access control): 다른클래스가특정한필드나메소드에접근하는 것을제어하는것 3 멤버수준에서의접근제어 4

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

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

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

More information

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

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

More information

PowerPoint Template

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

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

6장.key

6장.key JAVA Programming 1 2 3, -> () 3 Project FileIO WebFile.class FileCopy.class FileRW.class Tools.class Graphic DObject.class Line.class Rect.class Circle.class Project/FileIO/Tools.class Project/UI/Tools.class

More information

09-interface.key

09-interface.key 9 Database insert(record r): boolean find(key k): Record 1 Record getkey(): Key * Record Key Database.? Key equals(key y): boolean Database insert(record r): boolean find(key k): Record * Database OK 1

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

자바 프로그래밍

자바 프로그래밍 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

Microsoft Word - java18-1-final-answer.doc

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

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

C++ Programming

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

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 명품 JAVA Essential 1 2 학습목표 1. 패키지개념이해 2. 사용자패키지만들기 3. 자바에서제공하는표준패키지 4. Object 클래스활용 5. 박싱 / 언박싱을이해하고 Wrapper 클래스활용 6. String과 StringBuffer 클래스활용 7. StringTokenizer 클래스활용 8. Math 클래스활용 패키지개념과필요성 3 * 3 명이분담하여자바응용프로그램을개발하는경우,

More information

소프트웨어공학개론 강의 5: 객체지향개념 최은만동국대학교컴퓨터공학과

소프트웨어공학개론 강의 5: 객체지향개념 최은만동국대학교컴퓨터공학과 소프트웨어공학개론 강의 5: 객체지향개념 최은만동국대학교컴퓨터공학과 왜객체지향인가? l 절차적패러다임 vs. 객체지향패러다임 l 뭐가다르지? 2 C 언어 l 프로그램은데이터와함수로구성 l 함수는데이터를조작 l 프로그램을조직화하기위해 l 기능적분할 l 자료흐름도 l 모듈 Main program global data call call call return return

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 명품 JAVA Essential 1 2 학습목표 1. 패키지개념이해 2. 사용자패키지만들기 3. 자바에서제공하는표준패키지 4. Object 클래스활용 5. 박싱 / 언박싱을이해하고 Wrapper 클래스활용 6. String과 StringBuffer 클래스활용 7. StringTokenizer 클래스활용 8. Math 클래스활용 1 패키지개념과필요성 3 * 3

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

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

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

More information

PowerPoint Presentation

PowerPoint Presentation 데이터처리프로그래밍 Data Processing Programming 08 객체와클래스 목차 1. 객체와클래스 2. 인스턴스변수, 클래스변수 3. 클래스매직메소드 4. 클래스의상속 데이터처리프로그래밍 (Data Processing Programming) - 08 객체와클래스 3 1. 객체와클래스 객체 Object 객체란존재하는모든것들을의미 현실세계는객체로이루어져있고,

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 15. 다형성과가상함수 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 가상함수 (Virtual Function) 기본 사후바인딩 (late binding) / 동적바인딩

More information

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드] Class 접근제어 인터페이스 514760-1 2019 년봄학기 4/9/2019 박경신 Protected 는같은패키지내와파생클래스에서사용가능 public class Car { private boolean disel; // private은파생클래스에서사용하지못함 protected boolean gasoline; protected int wheel = 4; protected

More information

쉽게

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

More information

Microsoft PowerPoint 장강의노트.ppt

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

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 클래스와객체 I 이번시간에서학습할내용 클래스와객체 객체의일생 메소드 필드 UML 직접클래스를작성해봅시다. 클래스의구성 클래스 (class) 는객체의설계도라할수있다. 클래스는필드와메소드로이루어진다. 필드 (field) 는객체의속성을나타낸다. 메소드 (method) 는객체의동작을나타낸다. 클래스정의의예 class Car { // 필드정의 public int speed;

More information

Microsoft PowerPoint - Chapter 6.ppt

Microsoft PowerPoint - Chapter 6.ppt 6.Static 멤버와 const 멤버 클래스와 const 클래스와 static 연결리스트프로그램예 Jong Hyuk Park 클래스와 const Jong Hyuk Park C 의 const (1) const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; // 컴파일오류 3 C 의 const (1)

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

Spring Data JPA Many To Many 양방향 관계 예제

Spring Data JPA Many To Many 양방향 관계 예제 Spring Data JPA Many To Many 양방향관계예제 오라클자바커뮤니티 (ojc.asia, ojcedu.com) 엔티티매핑 (Entity Mapping) M : N 연관관계 사원 (Sawon), 취미 (Hobby) 는다 : 다관계이다. 사원은여러취미를가질수있고, 하나의취미역시여러사원에할당될수있기때문이다. 보통관계형 DB 에서는다 : 다관계는 1

More information

05-class.key

05-class.key 5 : 2 (method) (public) (private) (interface) 5.1 (Method), (public method) (private method) (constructor), 3 4 5.2 (client). (receiver)., System.out.println("Hello"); (client object) (receiver object)

More information

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

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

More information

Modern Javascript

Modern Javascript ES6 - Arrow Function Class Template String Destructuring Default, Rest, Spread let, const for..of Promises Module System Map, Set * Generator * Symbol * * https://babeljs.io/ Babel is a JavaScript compiler.

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

슬라이드 1

슬라이드 1 4 장클래스다이어그램 구성요소 객체와클래스 클래스추출 한빛미디어 ( 주 ) 학습목표 클래스의개념과구성요소를이해한다. 클래스추출과관계를학습한다. 관계를코드로이해한다. 2 학습목표 클래스의구성요소 클래스이름 (class name) 공통의속성, 메서드 ( 오퍼레이션 ), 관계, 의미를공유하는객체들의집합에대한기술이다. 속성 (attributes) 클래스의구조적특성에이름을붙인것으로구조적특성에해당하는인스턴스가보유할수있는값의범위를기술한다.

More information

비긴쿡-자바 00앞부속

비긴쿡-자바 00앞부속 IT COOKBOOK 14 Java P r e f a c e Stay HungryStay Foolish 3D 15 C 3 16 Stay HungryStay Foolish CEO 2005 L e c t u r e S c h e d u l e 1 14 PPT API C A b o u t T h i s B o o k IT CookBook for Beginner Chapter

More information

PowerPoint 프레젠테이션

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

More information

Microsoft PowerPoint - 04_OOConcepts(2010).pptx

Microsoft PowerPoint - 04_OOConcepts(2010).pptx LECTURE 4 객체지향개념 Object-Oriented Oi Oriented dc Concepts 내가가진도구가망치뿐이라면모든문제가다못으로보인다. 최은만, CSE 4039 소프트웨어공학 Old Way 프로그램은데이터와함수로구성 함수는데이터를조작 프로그램을조직화하기위해 기능적분할 자료흐름도 모듈 Main program global data call call

More information

슬라이드 1

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

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 4 (Object) (Class) (Instance) (Method) (Constructor) Memory 1 UML 1 @ & 1 (Real World) (Software World) @ &.. () () @ & 2 (Real World) (Software World) OOA/ Modeling Abstraction Instantiation

More information

슬라이드 1

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

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

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

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 객체지향프로그래밍 (OOP: object-oriented programming) 은우리가살고있는실제세계가객체 (object) 들로구성되어있는것과비슷하게, 소프트웨어도객체로구성하는방법이다. 객체는상태와동작을가지고있다. 객체의상태 (state) 는객체의속성이다. 객체의동작 (behavior) 은객체가취할수있는동작 ( 기능 ) 이다. 객체에대한설계도를클래스 (class)

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

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

(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 - CSharp-10-예외처리

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

More information

Microsoft PowerPoint - Java7.pptx

Microsoft PowerPoint - Java7.pptx HPC & OT Lab. 1 HPC & OT Lab. 2 실습 7 주차 Jin-Ho, Jang M.S. Hanyang Univ. HPC&OT Lab. jinhoyo@nate.com HPC & OT Lab. 3 Component Structure 객체 (object) 생성개념을이해한다. 외부클래스에대한접근방법을이해한다. 접근제어자 (public & private)

More information

유니티 변수-함수.key

유니티 변수-함수.key C# 1 or 16 (Binary or Hex) 1:1 C# C# (Java, Python, Go ) (0101010 ). (Variable) : (Value) (Variable) : (Value) ( ) (Variable) : (Value) ( ) ; (Variable) : (Value) ( ) ; = ; (Variable) : (Value) (Variable)

More information