본문 바로가기
반응형

자바 상속4

[자바AP연습문제] 09.Inheritance [자바AP연습문제] 09.Inheritance *09.Inheritance 단원의 복습내용은 아래 "더보기" 클릭 더보기 In this chapter you learned about inheritance. In an object-oriented program you write classes that define what objects of each class know (instance variables) and can do (methods). One class can inherit object instance variables and methods from another, which makes the amount of code that you have to write smaller and makes th.. 2024. 3. 29.
[자바기초.013] 상속과 생성자 [자바기초.013] 상속과 생성자 [1] 상속 관계에서 private 변수를 어떻게 다룰것인가? subclass는 자신이 확장하는 superclass에서 public method를 상속하지만 superclass의 private instance variable에 직접 액세스할 수는 없습니다. 그리고 subclass는 superclass의 생성자(constructor)를 상속하지 않습니다. 하지만 상속된 인스턴스 변수는 적절하게 초기화되어야 합니다. 그렇지 않으면 상속된 메서드(method) 중 어느 것도 제대로 작동하지 않을 것입니다. 그렇다면 subclass가 superclass의 private variable을 어떻게 초기화할 수 있을까요? [예제1] 아래의 상속 관계를 가지는 코드를 보고 생성자 부분.. 2024. 3. 13.
[자바기초.012] 상속(Inheritance) [자바기초.012] 상속(Inheritance) [1] 상속(Inheritance) 란? Object-Oriented programming에서 가장 큰 특징 중 하나가 상속(Inheritance)이다 일상 생활속에서 "상속"은 부모로부터 재산을 "상속 받는다"라고 할때 사용되는데, 자바에서도 그 의미가 비슷하다. 자바에서 모든 클래스(Class)는 attributes (instance variables / field) 와 behaviors (methods)를 다른 클래스로부터 상속받을 수 있다. 상속을 준 클래스는 "parent class or superclass"라고 하고, 상속을 받은 클래스는 "child class or subclass" 라고 부른다. 클래스 상속을 받기 위해서 Java keywor.. 2024. 3. 13.
[Java Class.06] 상속(Inheritance) [Java Class.06] 상속(Inheritance) 1.클래스 상속(Class inheritance) 부모가 자식에게 상속을 하듯이, 객체 지향 프로그램에서도 부모 클래스의 멤버를 자식 클래스에게 상속할 수 있다. 부모 클래스를 상위 클래스라고 부르기도 하고, 자식 클래스를 하위 클래스 or 파생 클래스라고 부른다. 상속은 이미 잘 개발된 클래스를 재사용하는 방법이므로 코드의 중복을 줄여준다. HTML 삽입 미리보기할 수 없는 소스 HTML 삽입 미리보기할 수 없는 소스 HTML 삽입 미리보기할 수 없는 소스 2.부모 생성자 호출(Super Constructor) 자바에서는 자식 객체를 생성하면, 먼저 부모 객체가 생성되고 그 다음에 자식 객체가 생성된다. 모든 객체는 클래스의 생성자(Constru.. 2024. 2. 23.
728x90
반응형