From ed103cef0f458d82423001ae8f0008131ac94858 Mon Sep 17 00:00:00 2001 From: "bit\\bitcamp" Date: Thu, 20 Jun 2024 12:48:51 +0900 Subject: [PATCH] =?UTF-8?q?240620=20=EC=A0=95=EB=8B=A4=EC=9D=80=20?= =?UTF-8?q?=EC=9D=B5=EB=AA=85=EA=B0=9D=EC=B2=B4=EA=B3=BC=EC=A0=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03. Anonymous/Anonymous.java" | 25 +++++++++++++++++++ .../03. Anonymous/AnonymousExample.java" | 22 ++++++++++++++++ .../03. Anonymous/Vehicle.java" | 5 ++++ 3 files changed, 52 insertions(+) create mode 100644 "\354\240\225\353\213\244\354\235\200/03. Anonymous/Anonymous.java" create mode 100644 "\354\240\225\353\213\244\354\235\200/03. Anonymous/AnonymousExample.java" create mode 100644 "\354\240\225\353\213\244\354\235\200/03. Anonymous/Vehicle.java" diff --git "a/\354\240\225\353\213\244\354\235\200/03. Anonymous/Anonymous.java" "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/Anonymous.java" new file mode 100644 index 0000000..fda31b7 --- /dev/null +++ "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/Anonymous.java" @@ -0,0 +1,25 @@ +package hw_240618; + +public class Anonymous { + Vehicle field = new Vehicle() { + + @Override + public void run() { + System.out.println("자전거가 달립니다."); + } + }; + void method1() { + Vehicle localVar = new Vehicle() { + + @Override + public void run() { + System.out.println("승용차가 달립니다."); + } + }; + localVar.run(); + } + + void method2(Vehicle v) { + v.run(); + } +} diff --git "a/\354\240\225\353\213\244\354\235\200/03. Anonymous/AnonymousExample.java" "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/AnonymousExample.java" new file mode 100644 index 0000000..0fadbf7 --- /dev/null +++ "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/AnonymousExample.java" @@ -0,0 +1,22 @@ +package hw_240618; + +public class AnonymousExample { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Anonymous anony = new Anonymous(); + anony.field.run(); + anony.method1(); + anony.method2( + new Vehicle() { + + @Override + public void run() { + System.out.println("트럭이 달립니다."); + + } + } + ); + } + +} diff --git "a/\354\240\225\353\213\244\354\235\200/03. Anonymous/Vehicle.java" "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/Vehicle.java" new file mode 100644 index 0000000..3d467b2 --- /dev/null +++ "b/\354\240\225\353\213\244\354\235\200/03. Anonymous/Vehicle.java" @@ -0,0 +1,5 @@ +package hw_240618; + +public interface Vehicle { + public void run(); +}