JAVA를 JAVA라

[JAVA & HTML] 21.06.08 본문

JAVA/JAVA 수업

[JAVA & HTML] 21.06.08

샛별KIM 2021. 6. 8. 17:09

<b></b>볼드

호출 시 id는 #, class는 .으로
#red{
color: blue;
font-size: 20pt;
}
.head1{
text-decoration: underline;
text-shadow: 2px 2px red;
font-style: italic;
background-color: orange;
}

<!-- 링크 -->
<link rel="stylesheet" href="index.css" type="text/css"> //이건 index.css로 보내줄때

<style type="text/css"> //이건 직접 적을때

//head안에 넣어줄것!!



<!-- 리스트 -->
<h1>list</h1>
<ul type="circle">
<li>소나무</li>
<li>대나무</li>
<li>사철나무</li>
</ul>

<ol type="1" start="9" reversed="reversed">
<li>퇴rms하기</li>
<li>장보기</li>
<li>요리하기</li>
<li>청소하기</li>
<li>잠자기</li>
</ol>

<!-- 다양한 input 타입 -->

<input type="text">
<input type="password">
<input type="number">
<input type="email">
<input type="file">
<input type="date">
<input type="range" max="10" min="1" value="5">
<input type="submit">
<input type="reset">
<input type="time">
<input type="month">
<input type="color">
<input type="button" value="버튼">
<button>버튼</button>

<select>
<option>사과</option>
<option>오렌지</option>
<option>포도</option>
<option>배</option>
<option>오이</option>
</select>


/////////////////////////////////////

/*
 * 메소드 오버라이드
 * 메소드 오버라이드는 객체지향 언어에서 자주 사용됩니다.
 * 상속받은 부모 메소드의 내용을 재정의해서
 * 자식에 맞게끔 활용하는 것입니다.
 * 
 * 주의할 점이 있습니다.
 * 1. 메소드의 형식은 상속받은 메소드와 동일해야 합니다.
 * 2. 접근제어자는 반드시 부모의 것과 같은 범위거나 더 큰 범위여야 합니다.
 * 3. 재정의된 메소드의 부모 메소드는 자식의 것에서는
 * 은닉(Hide)되어지기 때문에 직접적으로는 더이상 호출되지 않습니다.
 * 4. 은닉 된 부모 메소드를 호출할 때엔 super라는 
 *  부모 객체를 호출하는 키워드를 통해 호출합니다.
 */



/////////////////////////////////////////////////////////////////////////////
package jun08_inher;
//상속 및 오버라이드 다시
/*
 * 오버로드
 *  같은 이름의 메소드를 여러개 만드는 기술
 *  메소드 파라미터의 수, 순서, 타입이 달라야 합니다. =시그니처
 *  sleep()
 *  sleep(int age)
 *  sleep(int age, int name)
 *  this();
 *  this.메소드명();
 * 
 * 상속
 *  클래스를 디자인 할 때 중복되는 코드가 있다면
 *  이것을 상위 클래스에 몰아 넣고 내려받아 쓰는 것
 *  코드 중복을 줄일 수 있습니다.
 *  다형성으로 서로 연결할 수 있습니다.
 * 
 *  super();  부모 생성자 호출
 *  super.메소드명(); 부모 메소드 호출
 * 
 * 오버라이드 //상속! 재정의!!
 *  상속 관계에서만 생성
 *  부모의 메소드를 자식 클래스에서 자신의 상황에 맞게 
 *  재정의 해서 사용하는 것.
 *  접근제어자, 리턴 타입, 파라미터는 그대로
 * 
 */

class OldMan{
String name;
String ssn;

public OldMan(String name, String ssn) {
this.name = name;
this.ssn = ssn;
}

public void myInfo() {
System.out.println("이름은" + name + "입니다.");
System.out.println("주민번호는 " + ssn + "입니다.");
}
}

class NewMan extends OldMan{
String tel;

public NewMan(String name, String ssn, String tel) {
super(name, ssn);
// this.name = name;
// this.ssn = ssn;
this.tel = tel;
}

@Override
public void myInfo() {}

//이건 오버로드입니다!!파라미터값이 바뀐 같은 이름의 메소드이기 때문
public void myInfo(int count) { //얘는 파라미터 값이 추가되었기 때문에 더이상 오버라이드가 아님!!
//super.myInfo();
System.out.println("내 이름은 " + name + "입니다.");
System.out.println("생년월일은 " + ssn.substring(0, 6) + " 입니다.");
System.out.println("내 전화번호는 " + tel + "입니다.");
}
}

public class inher03 {
public static void main(String[] args) {

OldMan o01 = new OldMan("홍길동", "123456-1234567");
o01.myInfo();

System.out.println("");

NewMan n01 = new NewMan("김샛별", "126487-4542156", "010-1234-1324");
n01.myInfo();
}
}

/////////////////////////////////저어어엉리이이이//////////////////////////////////

'JAVA > JAVA 수업' 카테고리의 다른 글

[JAVA] 21.06.10  (0) 2021.06.10
[JAVA & DB] 21.06.09  (0) 2021.06.09
[JAVA & HTML] 21.06.07  (0) 2021.06.07
[JAVA] 21.06.04  (0) 2021.06.04
[JAVA] 생성자(메소드) 오버로딩(오버로드)  (0) 2021.06.03
Comments