switchOn / swithOff
extends 부모 클래스명
super
super()
를 함축적으로 내포하고 있다Pet pet = new Dog();
instanceof
pet instanceof Animal
abstract
키워드 사용abstract class AbstractAnimal
{
// 추상 메서드
abstract public void bark();
}
class Dog extends AbstractAnimal
{
public void bark()
{
System.out.println("Bow Bow");
}
}
Dog dog = new Dog();
dog.bark();
Bow Bow
interface Interface1
{
void method1();
}
interface Interface2
{
void method2();
}
class Implementation implements Interface2
{
public void method2() { };
public void method1() { };
}
abstract class AbstractImplementation implements Interface2
{
public void method1() { };
}
interface Interface3
{
// int test; [X]
int test = 5;
}
default
키워드interface Interface4
{
default void print()
{
System.out.println("default");
}
}
class Test implements Interface4
{
}
Test test = new Test();
test.print(); // default
class Test2 implements Interface4
{
// 오버라이드
public void print()
{
System.out.println("override");
}
}
Test1 test = new Test1();
test.print(); // override
interface Test
{
void nothing();
// 새로운 메서드를 추가하면 모든 구현 클래스에 해당 메서드를 추가해야 함
// void nothing1();
// default로 기본 메서드를 제공하면 컴파일 에러를 방지할 수 있음
default void nothing1()
{
};
}
class Class1 implements Test
{
@Override
public void nothing()
{
};
}
class Class2 implements Test
{
@Override
public void nothing()
{
};
}