zoukankan      html  css  js  c++  java
  • 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();
         }
     }
    

     

    三。例题

  • 相关阅读:
    Instruments之Core Animation学习
    Instruments之Allocations
    Instruments之Activity Monitor使用入门
    Instruments之相关介绍(一)
    快速理解Java中的五种单例模式
    iOS单例详解
    eclipse设置代码自动提示
    iOS-静态库,动态库,framework,bundle浅析(四)
    8.0docker的客户端和守护进程
    1.0 docker介绍
  • 原文地址:https://www.cnblogs.com/qiangini/p/13587308.html
Copyright © 2011-2022 走看看