只能兩個(gè)返回值嗎 或者需要加什么嗎?
//外部類
public class HelloWorld {
//外部類的方法
public void show(){
final int a =10;//外部類的常量
int b=20;//外部類的變量
//方法內(nèi)部類
class Inner{
int a =30;//內(nèi)部類的變量
int c=40;//內(nèi)部類的變量
public void print(){
System.out.println("方法外部類中的常量a:"+a);
System.out.println("方法外部類中的變量b:"+b);
System.out.println("方法內(nèi)部類中的變量a:"+a);
System.out.peintln("方法內(nèi)部類的變量c:"+c);
}
}
//創(chuàng)建內(nèi)部類對(duì)象
Inner mi=new Inner();
//調(diào)用內(nèi)部類方法
mi.print();
}
//測(cè)試方法內(nèi)部類
public static void main(String[] args){
//創(chuàng)建外部類對(duì)象
HelloWorld hello=new HelloWorld();
//調(diào)用外部類方法
hello.show();
}
}
2017-09-05
//外部類
public class HelloWorld {
//外部類的方法
? ? public void show(){
? ? ? ? final int a =10;//外部類的常量
? ? ? ? int b=20;//外部類的變量
? ? ? ? //方法內(nèi)部類
? ? ? ? class Inner{
? ? ? ? ? ? int a = 30;//內(nèi)部類的變量
? ? ? ? ? ? int c = 40;//內(nèi)部類的變量
? ? ? ? ? ? public void print(){
? ? ? ? ? ? System.out.println("方法外部類中的常量a:"+a);
? ? ? ? ? ? System.out.println("方法外部類中的變量b:"+b);
? ? ? ? ? ? System.out.println("方法內(nèi)部類中的變量a:"+a);
? ? ? ? ? ? System.out.println("方法內(nèi)部類的變量c:"+c);
? ? ? ? ? ? }
? ? ? ? }?
? ? ? ? //創(chuàng)建內(nèi)部類對(duì)象
? ? ? ? Inner mi=new Inner();
? ? ? ? //調(diào)用內(nèi)部類方法
? ? ? ? mi.print();
? ? }
? ? //測(cè)試方法內(nèi)部類
? ? public static void main(String[] args){
? ? ? ? //創(chuàng)建外部類對(duì)象
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? //調(diào)用外部類方法
? ? ? ? hello.show();
}
}
輸出變量C的語句你寫錯(cuò)了 你的寫法:System.out.peintln("方法內(nèi)部類的變量c:"+c); 應(yīng)該是System.out.println("方法內(nèi)部類的變量c:"+c);
變量b你已經(jīng)取到了啊
2017-08-13
沒看懂你要問什么