package cn.itcast.liukong;
public class TestThis {
public void jump(){
System.out.println("it's jumping now!");
}
public void run(){
jump();
this.jump();/*/d等效于裡面的代碼。this 關鍵字最大作用是讓類中一個方法,
通路該類的另一個方法或屬性。*/
TestThis dog = new TestThis();
dog.jump();
System.out.println("it's running now!!");
}
public class Testdog {
public static void main(String[]args){
TestThis Tdog=new TestThis();
Tdog.run();
}
public class TestStaticthis {
new TestStaticthis().run();//從新建立一個對象來調用非靜态方法。靜态方法無法通路非靜态方法
//run();
/*Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method run() from the type TestStaticthis
靜态方法無法通路非靜态方法。this.run()
at cn.itcast.liukong.TestStaticthis.main(TestStaticthis.java:5)*/
public void run(){
System.out.println("run!!");
public class TestRefenceTransfer {
public static void swap(DataWrap dw){
int tmp=dw.a;
dw.a=dw.b;
dw.b=tmp;
System.out.println("swap方法中的a的屬性值是:"+dw.a+";b的屬性值是:"+dw.b);
dw=null;
public static void main(String[]args){
DataWrap dw= new DataWrap();
dw.a=6;
dw.b=9;
swap(dw);
System.out.println("交換結束後,a屬性是"+dw.a+";b屬性的值是"+dw.b);
public class TestPrimitiveTransfer {
public static void swap(int a ,int b){
int tmp;
tmp=a;
a=b;
b=tmp;
System.out.println("a="+a+ ";b="+b);
public static void main(String[]args){
int a=3;
int b=90;
swap(a,b);
System.out.println("a="+a+";b="+b);
public class Resursive {
public static int intf(int n){//此番方法需要有傳回值為×××,故 非void 而int
if(n==0)
return 1;
else if (n==1)
return 4;
else
return 2*intf(n-1)+intf(n-2);//遞歸;;;
System.out.println(intf(3));
public class Person {
public String name;
public static int EyeNum;