package com.hiyo.HighClass; class House { private String name ; private float price ; public House(){//父类的构造方法 System.out.println("父类House中的构造方法!"); } public void setName(String name) { this.name = name ; } public void setPrice(float price) { this.price = price ; } public String getName(){ return this.name ; } public float getPrice() { return this.price ; } } class TownHouse extends House { public TownHouse(){ //子类的构造方法相当于又一个super() ; super() ;//可以不写,结果一样 System.out.println("子类的构造方法"); } private String town ; public String getTown(){ return this.town ; } public void setTown(String town) { this.town = town ; } } public class ExtendDemo2 { public static void main(String[] args) { TownHouse th = new TownHouse() ; th.setName("AA"); th.setPrice(30000.00f); th.setTown("BB"); System.out.println(th.getTown() + th.getName() + th.getPrice()); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)