java基础—继承连接
来源:互联网 发布:为知笔记思维导图插件 编辑:程序博客网 时间:2024/06/06 05:10
/*
老师用电脑上课。
问题领域中涉及两个对象。
毕老师,电脑。
分析其中的问题。
比如电脑蓝屏。冒烟啦。
*/
class LanPingException extends Exception
{
LanPingException(String msg)
{
super(msg);
}
}
class MaoYanException extends Exception
{
MaoYanException(String msg)
{
super(msg);
}
}
class NoPlanException extends Exception
{
NoPlanException(String msg)
{
super(msg);
}
}
class Computer
{
private int state = 2;
public void run()throws LanPingException,MaoYanException
{
if(state==1)
throw new LanPingException("电脑蓝屏啦!!");
if(state==2)
throw new MaoYanException("电脑冒烟啦!!");
System.out.println("电脑运行");
}
public void reset()
{
state = 0;
System.out.println("电脑重启");
}
}
class Teacher
{
private String name;
private Computer comp;
Teacher(String name)
{
this.name = name;
comp = new Computer();
}
public void prelect()throws NoPlanException
{
try
{
comp.run();
System.out.println(name+"讲课");
}
catch (LanPingException e)
{
System.out.println(e.toString());
comp.reset();
prelect();
}
catch (MaoYanException e)
{
System.out.println(e.toString());
test();
//可以对电脑进行维修。
// throw e;
throw new NoPlanException("课时进度无法完成,原因:"+e.getMessage());
}
}
public void test()
{
System.out.println("大家练习");
}
}
class ExceptionTest
{
public static void main(String[] args)
{
Teacher t = new Teacher("毕老师");
try
{
t.prelect();
}
catch (NoPlanException e)
{
System.out.println(e.toString()+"......");
System.out.println("换人");
}
}
}
/*
class NoAddException extends Exception
{}
void addData(Data d)throws NoAddException
{
连接数据库
try
{
添加数据。出现异常 SQLException();
}
catch(SQLException e)
{
//处理代码。
throw new NoAddException();
}
fianlly
{
关闭数据库。
}
}
*/
- java基础—继承连接
- Java基础—继承
- Java基础——继承
- Java基础——继承
- Java基础——继承
- Java基础——继承
- java—基础篇——继承
- JAVA基础——继承性
- Java基础——封装、继承、多态
- 黑马程序员——Java基础---继承
- JAVA基础 —— 继承、抽象、接口
- 黑马程序员——Java基础---继承
- 黑马程序员——Java基础--继承
- 黑马程序员——JAVA基础---继承
- 黑马程序员—Java基础—继承
- 程序员——java基础之继承
- java基础提高笔记——继承
- java基础(二)——继承
- 目标检测的图像特征提取之HOG特征
- Struts2拦截器使用方法
- C++的Json解析库:jsoncpp
- ehcache配置
- SQL2008 添加扩展属性 名称,值,以及表中的字段说明
- java基础—继承连接
- 在程序中调用其他进程或文档
- 取消下拉菜单折叠
- 哈希算法(Hash Algorithm)初探
- 华为——让华盛顿感到恐慌的中国公司(转载)
- .net 多文件上传 进度条
- TOJ 1134 Lotto 深搜
- GL 图像库
- ubuntu技巧(ubuntu 13.10)