Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Spring
- 함수
- 시큐어코딩
- kotlin
- git
- 오버라이드
- 게시판
- java#왕초보
- 상속
- 답글
- 안드로이드
- Android
- React
- snowpack
- SQL
- webpack
- 왕초보
- 쿠키
- 버전일치
- Spinner
- 스프링
- 스타일보험
- degit
- sub query
- 코틀린
- FIle
- 숫자
- java
- 미니게임
- parcel
Archives
- Today
- Total
YSHUSH
Interface 본문
Main class
/*
추상 메소드'만'을 포함하는 형태(template)
멤버변수를 포함할 수 없다
일반 메소드도 포함할 수 없다.
상속받은 후에 메소드를 정의한 후에 사용할 수 있다.
class의 사양을 파악할 수 있는 용도로 많이 사용한다.
확장성(다형성)에서 사용
전체를 묶는다(부모클래스 격이다)
다중 상속이 가능하다
*/
public class MainClass {
public static void main(String[] args) {
// MyInterface myi = new MyInterface(); -> 안됨
MyClass mycls = new MyClass();
mycls.method();
MyClass myi = new MyClass();
myi.method();
/*
MyInterface myinter = new MyInterface() {
@Override
public void method() {
// TODO Auto-generated method stub
}
};
// 하나의 인터페이스만 쓰고싶을땐 이렇게 쓰면 됨
*/
YouClass ycls = new YouClass();
ycls.func();
ycls.method();
// MyInterface myInterface = new MyClass();
MyInterface myInterface = new YouClass();
Object myobj = new MyClass();
Object youobj = new MyClass();
Object heobj = new MyClass();
// ***모든 객체를 담을 수 있는것이 Object클래스! / 주소공간으로 4바이트로 정해져있다.***
Object array[] = new Object[3];
array[0] = 123;
}
}
My interface
public interface MyInterface {
// private int number; 변수선언 안됨
// public void name() { } 함수(메소드)선언 안됨
public void method();
}
You interface
public interface YouInterface {
public void func();
}
My class
public class MyClass implements MyInterface {
@Override
public void method() {
System.out.println("MyClass method()");
}
}
You class
public class YouClass implements MyInterface, YouInterface{
@Override
public void func() {
System.out.println("YouClass func()");
}
@Override
public void method() {
System.out.println("YouClass method()");
}
}
He class
public class HeClass /* extends Object */{ // Object -> 최상위클래스, 텅빈통, 원래는 기본으로 적혀있었으나 빠짐(디폴트값)
// ↑↑↑↑↑↑↑↑ 기본상속자(기본으로 있는것이라 생략되어있음)
}
'Coding > Java' 카테고리의 다른 글
Final (0) | 2021.12.17 |
---|---|
Name card(interface) (0) | 2021.12.17 |
Abstract class (0) | 2021.12.17 |
Over ride3 (0) | 2021.12.16 |
Over ride.2 (0) | 2021.12.16 |