Test7.1
来源:互联网 发布:永宏fb编程电缆制作 编辑:程序博客网 时间:2024/06/06 17:45
树上的第六章我看了一下,觉得好麻烦,就没有深入研究,题目也没有做,直接跳到第七章
这一题中,我定义了Fruit 和Banana两个类,Fruit相当于基类,Banana是派生类,派生类中定义了一个基类的引用然后对他初始化。。。
class Fruit
{private String color;private double weight;
private int price;
//First fruit constructor
Fruit()
{System.out.println("A king of fruit");color="Red";weight=0;price=0;}
//second fruit constructor
Fruit(String c,double w,int p)
{System.out.println("A kind of fruit");color=c;weight=w;price=p;}
public String toString()
{
return
"Color= "+color+"; Weight= "+weight+"; Price= "+price;
}
}
class Banana
{
private String size;
private Fruit f;
//first banana constructor
Banana()
{
System.out.println("A banana ");
size="Big";
f=new Fruit();
}
//second banana constructor
Banana(String s,Fruit fr)
{System.out.println("A banana ");
size=s;
f=fr;
}
public String toString()
{
return
"Size= "+size+" "+f;
}
}
public class Test1
{
public static void main(String[] args) {
Fruit fu=new Fruit("Yellow",2.1,41);
System.out.println(fu);
Banana ba=new Banana("Small",fu);
System.out.println(ba);
}
}
0 0
- Test7.1
- test7
- test7
- test7
- test7-1(日期结构体)
- test7.2
- Test7.5
- test7.6
- test7.7
- test7.8
- test7.9
- Test7.10
- test7.11
- test7.12
- test7.13
- test7.14
- test7.15
- test7.16
- upgrade from 12.04 to 14.04
- Linux Xargs命令详解
- 安卓客户端与html js 交互
- leveldb设计分析之log
- Maven3路程(五)用Maven创建Hibernate项目
- Test7.1
- 固比固布局 css3
- 一篇关于IOS适配很好的文章
- AngularJs过滤器
- Opencv新版本模块结构
- C#里virtual和override
- shell mkfifo 阻塞式管道
- Android实战简易教程<十二>(ViewFlipper实现幻灯效果)
- Android ViewGroup事件分发机制(requestDisallowInterceptTouchEvent方法)