继承习题

 
   

第三题

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));
    
    
        
       
    
    }

}

 

转载于:https://www.cnblogs.com/OldZhao/p/4883377.html

你可能感兴趣的:(继承习题)