zoukankan      html  css  js  c++  java
  • java继承实例。

    定义了一个点类point,然后线条类line继承了point类,正方形类Suare继承point类。

    package test;
    
    import javax.swing.*;
    public class test {
        public static void main(String args[]){
            line AB = new line();
            System.out.println("AB的第一个坐标为:x="+AB.EGetx()+",y="+AB.EGety()+"."+"AB的第二个坐标为:x="+AB.EGetx()+",y="+AB.FGety()+".");
            Square ABCD = new Square();
            System.out.println("ABCD的第一个坐标为:"+ABCD.Get1x()+","+ABCD.Get1y()+"."
                                +"ABCD的第二个坐标为:x="+ABCD.Get2x()+","+ABCD.Get2y()+"."
                                +"ABCD的第三个坐标为:x="+ABCD.Get3x()+","+ABCD.Get3y()+"."
                                +"ABCD的第四个坐标为:x="+ABCD.Get4x()+","+ABCD.Get4y()+".");
        }
    }
    class point{
        private int x,y;
        static int pCount = 0;
        point(){x=10;y=20;pCount++;System.out.println("创建一个point,这个point为第:"+pCount+"个.");}
        point(int x,int y){this.x=x;this.y=y;pCount++;System.out.println("创建一个point,这个point为第:"+pCount+"个.");}
        static int GeipCount(){return pCount;}
        int Getx(){return x;}
        int Gety(){return y;}
    }
    class line extends point{
        static int lCount = 0;
        private    point E;
        private    point F;
        private float range;
        line()
        {
            E = new point();
            F = new point(1,2);
            range=1.5f;
            lCount++;
            System.out.println("创建一个line,这个line为第:"+lCount+"个.");
        }
        line(point E,point F,float range)
        {
            this.E=E;
            this.F=F;
            this.range=range;
            lCount++;
            System.out.println("创建一个line,这个line为第:"+lCount+"个.");
        }
        static int GeilCount(){return lCount;}
        int EGetx(){return E.Getx();}
        int EGety(){return E.Gety();}
        int FGetx(){return F.Getx();}
        int FGety(){return F.Gety();}
    }
    class Square extends point{
        private point A;
        private int range;
        static int sCount = 0;
        Square(){A = new point();range = 1;sCount++;System.out.println("创建一个Square,这个line为第:"+sCount+"个.");}
        Square(point A){this.A = A;range = 1;sCount++;System.out.println("创建一个Square,这个line为第:"+sCount+"个.");}
        Square(point A,int range){this.A = A;this.range = range;sCount++;System.out.println("创建一个Square,这个line为第:"+sCount+"个.");}
        int Get1x(){return A.Getx();}
        int Get1y(){return A.Gety();}
        int Get2x(){return A.Getx()+range;}
        int Get2y(){return A.Gety();}
        int Get3x(){return A.Getx();}
        int Get3y(){return A.Gety()+range;}
        int Get4x(){return A.Getx()+range;}
        int Get4y(){return A.Gety()+range;}
    }
  • 相关阅读:
    How to make BBED(Oracle Block Brower and EDitor Tool) on Unix/Linux/Windows
    直接路径读取对于延迟块清除的影响
    Mysql:日志管理:一般查询日志、慢速查询日志的
    Mysql:函数之二: miscellaneous functions
    Mysql:函数之三: date and time functions:重要的格式化函数
    Mysql:日志管理:综述
    Mysql:函数之三: date and time functions
    程序员阿BEN的SOHO生活
    网页常用Javascript
    优秀程序员的十个习惯
  • 原文地址:https://www.cnblogs.com/weijunyu/p/5713761.html
Copyright © 2011-2022 走看看