본문 바로가기
반응형

java inheritance3

[자바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.
728x90
반응형