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

     

    三。例题

  • 相关阅读:
    CRM详细介绍网址
    element上传多图片
    多图片上传WebForm
    MemCached原理
    Redis的原理
    Ninject用法详解
    SQLsugar和unity 的用法
    json中的转义字符的处理
    fiddler
    orm多表关系
  • 原文地址:https://www.cnblogs.com/qiangini/p/13587308.html
Copyright © 2011-2022 走看看