SCJP

---


public class app9_14
{  
 public static void main(String[] args)
 { 
  c2.Caaa aa=  (new c2()).getCaaa();//類別.static成員
  aa.set_num(5);
 } 
}
class c2{
 int n=0; 
   public Caaa getCaaa()//宣告在類別底下為類別的成員
 { Caaa obja = new Caaa();
  return obja;//也可以return Caaa();
 }
   class Caaa{//宣告在類別
   int num;
   void set_num(int n){
  }  
 
   }
  }
 
   

---

 public class app9_14 {  
 public static void main(String[] args) {
  c2.Caaa aa=  (new c2()).getCaaa();//類別.static成員
  aa.set_num(5); 
  (new c2.Caaa()
  {
  void set_num(int n)
   {
   int num = n;
   System.out.println("num="+num);
   }
  }
  ).set_num(10);//執行Caaa類別內.set_num副程式
  }
 }
 
class c2{
 static class Caaa{//宣告在類別物件
  int num;
 void set_num(int n){
    num = n;
  System.out.println("num="+num);
 }
}
 int n=0; 
   public Caaa getCaaa()//宣告在類別底下為類別的成員
 { Caaa obja = new Caaa();
  return obja;//也可以return Caaa();
 }
   }

---

 public class app9_14 {  
 public static void main(String[] args) {
  c2.Caaa aa=  (new c2()).getCaaa();//類別.static成員
  aa.set_num(5); 
  aa=null;  //物件設成空物件
  System.gc();//回收空物件的記憶體
  (new c2.Caaa(){
  void set_num(int n)
   {
   int num = n;
   System.out.println("num="+num);
   }
  }).set_num(10);//執行Caaa類別內.set_num副程式
 }
}
 
class c2{
 static class Caaa{//宣告在類別物件
  int num;
 void set_num(int n){
    num = n;
  System.out.println("num="+num);
 }
}
 int n=0; 
 
   public Caaa getCaaa()//宣告在類別底下為類別的成員
 { Caaa obja = new Caaa();
  return obja;//也可以return Caaa();
 }
   }
    
 ---第十章

 

 

public class app10_1 extends CCoin {
 private static double pi = 3.14;
 private double radius;

 public app10_1() {
  System.out.println("CCircle() constructor called ");
 }

 public static void main(String[] args) {
  System.out.println("建立子類別CCoin物件");
  CCoin objcc = new CCoin();
  System.out.println("建立父類別app10_1物件");
  app10_1 objpp = new app10_1();
 }

 public void setReadius(double r) {
  radius = r;
  System.out.println("radius=" + radius);
 }
}

class CCoin {
 private int value;

 public CCoin() {
  System.out.println("CCoin() constructor called");
 }

 public void setValue(int t) {
  value = t;
  System.out.println("value=" + value);
 }
}

---

 

public class app10_1 extends CCoin {
 private static double pi = 3.14;
 private double radius;

 public app10_1() {
  System.out.println("CCircle() constructor called ");
 }

 public static void main(String[] args) {
  System.out.println("建立子類別CCoin物件");
  CCoin objcc = new CCoin();
  System.out.println("建立父類別app10_1物件");
  app10_1 objpp = new app10_1();//建立父類別(app10_1)物件時,會先初始化子類別物件,執行子類別(CCoin)建構元,再初始化父類別,執行父類別建構元
 }

 public void setReadius(double r) {
  radius = r;
  System.out.println("radius=" + radius);
 }
}

class CCoin {
 private int value;

 public CCoin() {
  System.out.println("CCoin() constructor called");
 }

 public void setValue(int t) {
  value = t;
  System.out.println("value=" + value);
 }
}

---

 

public class app10_1 extends CCoin {
 private static double pi = 3.14;
 private double radius;

 public app10_1() {
  System.out.println("子類別建構元10_1() CCircle() constructor called ");
 }

 public static void main(String[] args) {
  System.out.println("建立子類別app10_1物件");
  app10_1 objpp = new app10_1();//建立子類別(app10_1)物件時,會先初始化父類別物件,執行子類別(CCoin)建構元,再初始化父類別,執行父類別建構元
 }

}

class CCoin {
 private int value;

 public CCoin() {
  System.out.println("父類別建構元CCoin() constructor called");
 }

 //public void setValue(int t) {
 // value = t;
 // System.out.println("value=" + value);
 //}
}

---test

public class cchi extends codd {
 private static double pi = 3.14;
 private double radius;

 public  cchi() {
  System.out.println("子類別建構元cchi() constructor called ");
 }

 public static void main(String[] args) {
  System.out.println("建立子類別cchi()物件");
  cchi objpp = new cchi();
  
  //建立子類別(app10_1)物件時,會先初始化父類別物件,執行子類別(CCoin)建構元,再初始化父類別,執行父類別建構元

 }
}

class codd {
 private int value;

 public codd() {
  System.out.println("父類別建構元codd() constructor called");
 }

 //public void setValue(int t) {
 // value = t;
 // System.out.println("value=" + value);
 //}
}

 

 ---完整

public class app10_1 extends CCoin {
 private static double pi = 3.14;
 private double radius;

 public app10_1() {
  System.out.println("app10_1() constructor called");
 }

 public static void main(String[] args) {
  System.out.println("建立子類別 CCoin 物件");
  CCoin objcc = new CCoin();
  System.out.println("建立父類別 app10-1 物件");
  app10_1 objbb = new app10_1();
 }

 public void setRadius(double r) {
  radius = r;
  System.out.println("radius=" + radius);
 }

 public void show() {
  System.out.println("area=" + pi * radius * radius);
 }
}

class CCoin {
 private int value;

 public CCoin() {
  System.out.println("CCoin() constructor called");
 }

 public void setRadius(int t) {
  value = t;
  System.out.println("value=" + value);
 }
}

 

 

 

玥君 發表在 痞客邦 PIXNET 留言(0) 人氣()