목록분류 전체보기 (65)
혜야의 코딩스토리
[상속관계] 1. 기존의 클래스로 새로운 클래스를 작성하는 것. (코드의 재사용) class 자식클래스 extends 부모클래스 { // …. } 2. 두 클래스를 부모와 자식으로 관계를 맺어주는 것. 3. 자손은 조상의 모든 멤버를 상속받는다. (생성자, 초기화 블록 제외) 4.자손의 멤버 개수는 조상보다 적을 수 없다. (같거나 많다.) class Parent { //부모 멤버 1개 int age; } class Child extends Parent { } //자식 멤버 1개 5.자손 클래스의 변경은 조상 클래스에 영향을 미치지 않는다. class Parents { //부모 멤버 1개 int age; } class Child extends Parent { //자식 멤버 2개 void play( ) {..

public class Employee2 {//조상클래스 protected String num; //사원번호 protected String name; //이름 protected String address;//주소 protected String email; //이메일 //기본생성자 Employee2() {} //매개변수가 4개인 생성자 public Employee2(String num, String name, String address, String email) { this.num = num; this.name = name; this.address = address; this.email = email; } } public class Manager2 extends Employee2 { private int ..

class Product { //조상클래스 int price; //제품의 가격 int bonusPoint; //제품구매 시 제공하는 보너스 점수 Product(int price) { this.price = price; bonusPoint= (int)(price/10.0); //보너스점수는 제품가격의 10% } } class Tv1 extends Product { //Product의 자손클래스 Tv1 Tv1() { //조상클래스의 생성자 Product(int price)를 호출한다. super(100); //Tv의 가격을 100만원으로 한다. } @Override //object클래스의 toString을 오버라이딩한다. public String toString() {return "Tv";} } class ..

public class Person { //멤버변수 private String name; private int height; private int weight; public Person() {//기본 생성자 this("고길동",170,60); //this()생성자 호출은 첫줄에 써야 함. } public Person(String name) { //매개변수가 1개인 생성자 this(name,190,100);//나와 이름이 같은 Person생성자 중 //매개변수 개수와 타입이 맞는 생성자를 호출 } public Person(String name, int height) {//매개변수가 2개인 생성자 this(name,height,70); } public Person(String name, int height,..

public class Person { //멤버변수 private String name; private int age; private String email; private String address; //private double height; //이름 //setter : set+변수명 public void setName(String name) { //name 지역변수 this.name = name; //this => 멤버변수iv를 가리킴 //멤버변수와 지역변수의 이름이 같을 때 멤버변수 앞에 this를 붙인다. } //getter : get+변수명 public String getName() { return name; } //나이 public void setAge(int age) { if(age 150..

public class Radio { //멤버변수(전역변수) //변수는 private으로 설정 private boolean onOff; private double channel; private int volume; //메소드는 public으로 설정 public double getChannel() { return channel; } public void setChannel(double ch) { channel = ch; //멤버변수(iv) = 로컬변수 } public int getVolume() { return volume; } public void setVolume(int vol) { volume = vol; } public boolean getonOff() { return onOff; } public ..