• 继承习题


    
    

    第三题

    package xin_learn;
    
    import org.omg.Messaging.SyncScopeHelper;
    
    class grandfather 
    {
        public grandfather()
        {
            System.out.println("爷爷");
        }
    }
    
    class father extends grandfather
    {
        public father()
        {
            System.out.println("爸爸");
        }
    }
    
    class son extends father
    {
       public son()
       {
           System.out.println("儿子");
       }
        
        public static void main(String[] args)
       {
           grandfather gf = new grandfather();
        
       }
    }

    第二题

    //父类
    package
    learn; public class Juxing { public String Bianhao; public Juxing(String bianhao) { Bianhao = bianhao; System.out.println("这是"+ bianhao + "号矩形"); } public double Mianji(double chang,double kuang) { return chang * kuang; } public double Duijiaoxian(double chang,double kuang) { return Math.sqrt((Math.pow(chang, 2)) + (Math.pow(kuang, 2))); } }
    //子类
    package learn;
    
    public class Zhengfangxing extends Juxing 
    {
        public Zhengfangxing(String bianhao) 
        {
            super(bianhao);
        }
        public double Duijiaoxian(double b)
        {
            return Math.sqrt(Math.pow(b, 2)*2);
        }
    
    }
    //实例
    package learn;
    
    public class Juxing_test {
    
        public static void main(String[] args) 
        {
            // TODO Auto-generated method stub
    
            
            Juxing jx = new Juxing("1");
    
            System.out.println("该矩形的面积为:" + jx.Mianji(12.4, 6));
            
            System.out.println("该矩形对角线长度为:" + jx.Duijiaoxian(12, 6));
        
        
        
            Juxing zfx = new Zhengfangxing("2");
            
            
            
            System.out.println("zfx的对角线长为:" + zfx.Duijiaoxian(3, 3));
        
        
            
           
        
        }
    
    }
  • 相关阅读:
    window.open()弹出窗口防止被禁
    实用Javascript代码片段
    php字符串常用函数
    PHP基本使用
    php开发环境搭建
    what is php?
    Front-end Developer Interview Questions
    jQuery Questions:Front-end Developer Interview Questions
    JS Questions:Front-end Developer Interview Questions
    HTML Questions:Front-end Developer Interview Questions
  • 原文地址:https://www.cnblogs.com/OldZhao/p/4883377.html
Copyright © 2020-2023  润新知