반응형
package hello;
class Pencil{
public void write() {
System.out.println("연필로 쓴다");
}
}
class Ballpoint{
public void writing() {
System.out.println("볼펜으로 쓴다.");
}
}
public class Mainclass {
public static void main(String[] args) {
Pencil pencil = new Pencil();
Ballpoint ballpoint = new Ballpoint();
pencil.write();
ballpoint.writing();
}
}
package hello;
interface Frindle {
public void write();
}
class Pencil implements Frindle {
public void write() {
System.out.println("연필로 쓴다.");
}
}
class Ballpoint implements Frindle {
public void write() {
System.out.println("볼펜으로 쓴다.");
}
}
public class Mainclass{
public static void main(String[] args) {
Frindle frindle = new Pencil();
frindle.write();
Frindle frindle1 = new Ballpoint();
frindle1.write();
}
}
package hello;
interface PhoneInterface {
final int TIMEOUT = 10000;
void sendCall();
void receiveCall();
default void printLogo() {
System.out.println("** phone **");
}
}
class SamsungPhone implements PhoneInterface {
@Override
public void sendCall() {
System.out.println("띠리리리링");
}
@Override
public void receiveCall() {
System.out.println("전화가 왔습니다.");
}
public void flash() {
System.out.println("전화기에 불이 켜졌습니다.");
}
}
public class Mainclass {
public static void main(String[] args) {
SamsungPhone phone = new SamsungPhone();
phone.printLogo();
phone.sendCall();
phone.receiveCall();
phone.flash();
}
}
package hello;
interface Mammal {
abstract void giveBirth();
}
abstract class Fish {
void swim() {
System.out.println("물고기는 헤엄치며 움직입니다.");
}
}
class Whale extends Fish implements Mammal{
public void giveBirth() {
System.out.println("고래는 새끼를 낳습니댜.");
}
public void swim() {
System.out.println("고래는 헤엄치며 움직입니다.");
}
}
public class Ifpr {
public static void main(String[] args) {
Whale w = new Whale();
w.swim();
w.giveBirth();
}
}
package hello;
class OuterClass1 {
void a() {
System.out.println("method a");
}
void b() {}
}
public class Anonymous {
public static void main(String[] args) {
OuterClass1 o = new OuterClass1() {
void a() {
System.out.println("새롭게 정의한 익명 클래스의 메서드입니다.");
}
};
o.a();
OuterClass1 ok = new OuterClass1();
ok.a();
}
}
새롭게 정의한 익명 클래스의 메서드입니다.
method a
반응형
'JAVA > 문법' 카테고리의 다른 글
[JAVA] 예외처리 (0) | 2020.01.05 |
---|---|
[JAVA] 추상클래스 (0) | 2020.01.04 |
[JAVA] 클래스 (0) | 2019.12.22 |
[JAVA] 배열 2 (0) | 2019.12.15 |
[JAVA] 배열 (0) | 2019.12.15 |