JAVA

· JAVA
/** * 내부클래스3 */ public class TestInner3 { public static void main(String[] args) { F f = new F(); f.print(); } // end of main } // end of class class F { int age = 3; static int tall = 4; public F() { System.out.println("클래스 F 의 생성자"); } void print() { int water = 10; // 지역변수 class G { // 내부클래스 - 지역변수 영역 : 메서드 내부에서만 사용가능 int a = 7; //static int b = 8; // 내부클래스 - 지역변수 영역 에서는 static멤버불가 public G()..
· JAVA
/** * 내부클래스2 */ public class TestInner2 { public static void main(String[] args) { D.tall = 3; D.E.water++; // 객체 생성없이 바로 접근할 수 있다 D.E.sss(); D.E eee = new D.E(); // D 클래스의 static 멤버클래스 생성 방법 eee.cnt++; eee.print(); } // end of main } // end of class class D { int age; static int tall; static class E { // 내부inner 클래스 - static 클래스 int cnt = 6; static int water = 10; // static 멤버를 가질수 있다 public E(..
· JAVA
/** * 내부(inner)클래스, 중첩(nested)클래스 */ public class TestInner { public static void main(String[] args) { A aaa = new A(); aaa.a = 3; A.B bbb = aaa.new B(); // 내부inner 클래스 - 인스턴스 클래스 객체생성 A.B ccc = new A().new B(); } // end of main } // end of class class A { // 외부outer 클래스 int a; // 인스턴스 변수 static int b; // static 변수 class B { // 내부inner 클래스 - 인스턴스 클래스 int inb; // 인스턴스 변수 //static int ins; // 인스턴스..
· JAVA
/** * interface 다형성 활용 */ public class TestUnit { public static void main(String[] args) { Marine m = new Marine(); // 20 Tank t = new Tank(); // 100 Dropship d = new Dropship(); // 60 Scv s = new Scv(); m.hp -= 10; // 10 t.hp -= 50; // 50 d.hp -= 10; // 50 s.repair(t); // 탱크 수리 s.repair(d); // 드랍십 수리 //s.repair(m); // 마린 수리 Repairable r1 = t; // 다형성 Repairable r2 = d; // 다형성 //Repairable r3 = m..
· JAVA
/** * interface 활용 */ public class TestProduct { public static void main(String[] args) { } // end of main } // end of class interface ProductInterface { public abstract void displayProductInfo(); // 추상클래스 } abstract class Product implements ProductInterface { String company; String name; int price; } class Television extends Product { int inchSize; public void displayProductInfo() { System.out...
· JAVA
/** * interface 의 상속 */ public class TestInterface2 { public static void main(String[] args) { //Movable m = new Movable(); // interface 는 객체를 생성할 수 없다 //Attackable a = new Attackable(); //Fightable f = new Fightable(); Fight f = new Fight(); f.attack(); f.move(); System.out.println(f.a); System.out.println(f.m); } // end of main } // end of class interface Movable { public static final int m = ..
· JAVA
/** * interface : abstract class 보다 더 추상화도가 높은 개념 */ public class TestInterface { public static void main(String[] args) { } // end of main } // end of class interface Cable { // ~able 로 끝나는 이름으로 작성하자 public static final int c = 3; // 초기화까지 해야한다 public int d = 3; //void a() { } // 일반메서드는 올수 없다(구현부body를 작성하면 안됨) public abstract void b(); // 추상메서드는 올수 있다 void c(); // 부족한 제어자를 컴파일러가 추가해준다 public vo..
· JAVA
/** * 열거형 * 요일을 표현하는 상수 */ public enum Week { MONDAY,TUESDAY,WENDESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY }
· JAVA
/** * 추상 클래스 활용 */ public class TestTv { public static void main(String[] args) { } // end of main } // end of class class Tv { int volumn; int channel; boolean power; void volumnUp() { volumn++; } void powerOnOff() { power = !power; } } // end of class Tv class CaptionTv extends Tv { boolean caption; void powerOnOff() { super.powerOnOff(); } void caption(String text) { if (caption) System.out.p..
· JAVA
/** * 추상클래스 활용 */ public class TestUnit { public static void main(String[] args) { //Unit u = new Unit(); // 추상클래스로는 객체를 생성할 수 없다 Marine m = new Marine(); Tank t = new Tank(); Dropship d = new Dropship(); m.stimPack(); m.move(3, 1); t.changeMode(); t.move(2, 4); d.load(); d.move(5, 8); System.out.println(); ////////////////////////////// movePrint(m); movePrint(t); movePrint(d); ////////////////..
'JAVA' 카테고리의 글 목록