'Java > Modifier(제어자)' 카테고리의 다른 글
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
package com.inner2;//내부 클래스 원하는 변수 출력하기
class Outer2{
int a = 100;
//멤버 내부 클래스
class Inner2{
int a = 200;
public void method1(){
int a = 300;
System.out.println("a = "+a);
System.out.println("this.a = "+Inner2.this.a);
System.out.println("this.a = "+this.a);
System.out.println("Outer2.this.a = "+ Outer2.this.a);
//위치가 명확하지 않으면 위치를 써놓고 this를 쓰는것이 좋음
}
}
}
public class InnerTest2 {
public static void main (String[] args){
Outer2.Inner2 oi = new Outer2().new Inner2();
oi.method1();
}
}a = 300
| 예비 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
package com.inner4;//내부 클래스 static 알아보기
public class InnerEx {
//내부 클래스가 static 변수를 갖고 있으면
//클래스를 static으로 지정해야 함
static class StaticInner{
int iv = 200;
static int cv = 300;
}
public static void main(String[] args){
InnerEx.StaticInner i = new InnerEx.StaticInner();
System.out.println(i.iv);
System.out.println(InnerEx.StaticInner.cv);
}
}200
300
| 예비 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
package com.inner3;//내부 클래스 지역변수 상수 호출
public class InnerTest {
int a = 100;
public void innerMethod(){
int localVar = 500; //지역변수
final int num =100; //상수
class Inner{
int b = 200;
public void getDate(){
//InnerTest의 멤버변수는 호출 가능
System.out.println("a = "+a);
//Inner의 멤버변수는 당연히 호출가능
System.out.println("b = "+b);
/*내부 클래스가 포함된 메소드의 지역변수 호출불가
System.out.println("lovalVar = "+localVar);*/
//상수는 호출 가능
System.out.println("num = "+num);
}
}
//메모리에 올리기
Inner i = new Inner();
i.getDate();
}
public static void main(String[] args){
InnerTest i = new InnerTest();
i.innerMethod();
}
}a = 100
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
| 상수 final (0) | 2012.04.11 |
package com.inner;//내부 클래스
class Outer{
int a =100;
//멤버 내부 클래스
class Inner{
int b = 200;
}
}
public class InnerTest {
public static void main(String[] args){
Outer ot = new Outer();
System.out.println("ot = "+ot);
System.out.println(ot.a);
//내부 클래스 객체 생성
Outer.Inner oi = ot.new Inner();
System.out.println("oi = "+oi);
System.out.println(oi.b);
}
}
class Outer{
//멤버 변수
int a = 100;
//멤버 내부 클래스
class Inner{
int b = 200;
public void make(){
//멤버 내부 클래스는 내부 클래스를 포함하는 \
//클래스(Outer)의 멤버변수 호출 가능
System.out.println("a = "+a);
System.out.println("B = "+b);
}
}
}
public class InnerTest {
public static void main(String[] args){
/*Outer ot = new Outer();
Outer.Inner oi = ot.new Inner();
oi.make();*/
Outer.Inner oi = new Outer().new Inner();
oi.make();
}
}
package com.inner3;
public class LocalInner {
public void innerTest(){
//로컬 내부 클래스
class Inner{
public void getDate(){
System.out.println("Local 내부 클래스 호출!!");
}
}
Inner i = new Inner();
i.getDate();
}//innerTest()끝
public static void main(String[] args){
LocalInner outer = new LocalInner();
outer.innerTest();
}
}
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |
| 상수 final (0) | 2012.04.11 |
package com.finalex;
class Me{
int var = 100;
//메소드에 final을 지정하면 해당 메소드는 상속되지만
//자식 클래스에서 재정의 되지 않음
public final void setVar(int var){
this.var = var;
}
}
public class MeEx extends Me{
/*부모 클래스의 setVar가 final 이기 때문에 재정의 불가능
public void setVar(int var){
System.out.println(var);
}*/
public static void main(String[] args){
MeEx m = new MeEx();
m.setVar(300);
System.out.println(m.var);
}
}
300
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 상수 final (0) | 2012.04.11 |
package com.finalex;
class FinalMember{
final int A = 10;//상수 (대문자가 좋음)(초기화)
public void setA(int a){
//상수는 프로그램에서 처음 사용할때 초기화는 가능하지만
//한번 초기화한 후 변경 불가능
//this.A = a;
}
}
public class FinalTest01 {
public static void main(String[] args){
FinalMember ft = new FinalMember();
ft.setA(100);
System.out.println(ft.A);
}
}
10
| 내부 클래스 호출에 대해서 (0) | 2012.04.11 |
|---|---|
| 내부 클래스 static (0) | 2012.04.11 |
| 내부 클래스 지역변수 상수 호출 (0) | 2012.04.11 |
| 내부 클래스 (0) | 2012.04.11 |
| 클래스와 상수 (0) | 2012.04.11 |