331929879

          2007年10月16日 #

          繼承類


          class Father
          {
           int age;
           String name;
           void eat()
           {
            System.out.println("吃饃!");
           }
          }
          class Son extends Father
          {
           int height;
           void eat()
           {
            super.eat();
            System.out.println("喝酒");
           }
          }
          class Ex
          {
           public static void main(String args[])
           {
            Son p=new Son();
            Father p1=new Son();
            p1.eat();
            p.eat();
           }
          }

          posted @ 2007-10-16 14:47 小飛 閱讀(165) | 評(píng)論 (0)編輯 收藏

          2007年10月12日 #

          復(fù)數(shù)運(yùn)算

          class Complex{
           double real;
              double image;

              public Complex add(Complex another){
            Complex res = new Complex();
            res.real = real + another.real;
            res.image = image + another.image;
            return res;
              }
              
           public Complex minus(Complex another){// 當(dāng)前復(fù)數(shù)與方法參數(shù)another相減;
            Complex r = new Complex();
            r.real = real - another.real;
            r.image = image - another.image;
            return r;
           }
           
           public Complex multi(Complex another){ //當(dāng)前復(fù)數(shù)與方法參數(shù)another相乘(注意復(fù)數(shù)相乘); 
            Complex r = new Complex();
            r.real = real * another.real - image * another.image;
            r.image = real * another.image + image * another.real ;
            return r;
           }
           
           public void disp(){
            if( image == 0 ){
             System.out.print(real);
            }
            else
            {
             System.out.print(real + " + " + image + "i");
            }
           }
           
           public Complex(double real , double image){
            this.real = real;
            this.image = image ;
           }
           public Complex(){
            this(0 , 0);
           }
           
           public static void main (String[] args) {
            Complex c1 = new Complex(2 , 3);
            Complex c2 = new Complex(5 , 4);
            Complex res;
            
            c1.disp();
            System.out.print("  +   ");
            c2.disp();
            System.out.print("  =   ");
            c1.add(c2).disp();
            System.out.println();
            
            c1.disp();
            System.out.print("  -   ");
            c2.disp();
            System.out.print("  =   ");
            c1.minus(c2).disp();
            System.out.println();
            
            
            c1.disp();
            System.out.print("  *   ");
            c2.disp();
            System.out.print("  =   ");
            c1.multi(c2).disp();
            System.out.println();
              }
          }

          posted @ 2007-10-12 09:13 小飛 閱讀(281) | 評(píng)論 (0)編輯 收藏

          2007年10月11日 #

          一個(gè)繼承類

          class Circle
          {
           int r;
           static double PI=3.14;
           public int GetR(int r)
           {
            this.r=r;
            return r;
           }
           public void GetZ()
           {
            System.out.println(2*PI*r);
           }
           public void GetArea()
           {
            System.out.println(PI*r*r);
           }
          }
          class Cylinder extends Circle
          {
           int height;
           public void GetCylinder(int r,int height)
           {
            this.r=r;
            this.height=height;
           }
           public void GetZ()
           {
            System.out.println(PI*r*r*height);
           }
           public void GetArea()
           {
            System.out.println(2*PI*r*r+2*PI*height);
           }
          }
          class Ex
          {
           public static void main(String args[])
           {
            Circle p=new Circle();
            System.out.println( p.GetR(2));
            p.GetZ();
            p.GetArea();
            Cylinder p1=new Cylinder();
            p1.GetZ();
           }
          }

          posted @ 2007-10-11 15:09 小飛 閱讀(180) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題  
          主站蜘蛛池模板: 来凤县| 江西省| 漯河市| 饶平县| 天津市| 蓬莱市| 湖南省| 榆社县| 鄂伦春自治旗| 安溪县| 玉溪市| 科技| 务川| 乌鲁木齐县| 曲周县| 东台市| 文化| 华池县| 岳普湖县| 沙田区| 蓬安县| 台州市| 车险| 岳阳县| 江华| 荔浦县| 同德县| 鱼台县| 突泉县| 茌平县| 藁城市| 象山县| 玛纳斯县| 金山区| 六盘水市| 温宿县| 苗栗市| 三河市| 涞源县| 杂多县| 芒康县|