• java学习54天2020/8/28


    定义一个Document类,有数据成员name,从Document派生Book类,增加数据成员pageCount。

         private String name; //书名
         public Document(String name) {
             this.name = name;
         }
         public String getName() {
             return name;
         }
     }
    
     public class Book extends Document{
         private int pageCount; //页数
         public Book(String name,int pageCount) {
             super(name);
             this.pageCount=pageCount;
         }
         public void display() {
             System.out.println("Name:"+getName());
             System.out.println("PageCount:"+pageCount);
         }
         public static void main(String[] args) {
             Book b=new Book("Java",444);
             b.display();
         }
     }
    

     

     定义一个Object1类,有数据成员weight及相应的操作函数,由此派生出Box类,增加数据成员height和width及相应的操作函数,声明一个Box对象,观察构造函数的调用顺序。

    class Object1{
         private float weight;
         public Object1(float weight) {
             this.weight=weight;
             System.out.println("构造Object1类");
         }
         public float getWeight() {
             return weight;
         }
     }
     public class Box extends Object1{
         private float height;
         private float width;
         public Box(float weight,float height,float width) {
             super(weight);
             this.height=height;
             this.width=width;
             System.out.println("构造Box类");
         }
         public void display() {
             System.out.println("The weight of the box is "+getWeight());
             System.out.println("The height of the box is "+height);
             System.out.println("The width of the box is "+width);
         }
         public static void main(String[] args) {
             Box b=new Box(1.5554f,1,1.55f);
             b.display();
         }
     }
    

     

    三。例题

  • 相关阅读:
    3. applicationCache
    9. 水平垂直居中的方法
    2. 贝塞尔曲线bezierCurveTo
    相识python 之小数据池 集合
    相识python --------- 列表 元祖 range 范围
    相识python while循环 代码块 编码初识 运算符
    相识python第二步:变量 注释 str int bool 用户交换 流程控制语句的解释用法
    python学习基础知识
    python的基础知识
    我对python的见解
  • 原文地址:https://www.cnblogs.com/qiangini/p/13587308.html
Copyright © 2020-2023  润新知