Abstractcc.java
|
Delta.java
|
four.java
|
package cn.com.farsight.java;
public abstract class Abstractcc {
public abstract double perimeter();
public abstract String getType();
}
|
package cn.com.farsight.java;
public class Delta extends Abstractcc {
private int a, b, c;
@Override
public double perimeter() {
// TODO Auto-generated method stub
return a + b + c;
}
@Override
public String getType() {
// TODO Auto-generated method stub
return "三角形";
}
}
|
package cn.com.farsight.java;
public class Four extends Abstractcc {
private int a, b, c, d;
@Override
public double perimeter() {
// TODO Auto-generated method stub
return a + b + c + d;
}
@Override
public String getType() {
// TODO Auto-generated method stub
return "四边形";
}
}
|
接口
|
智能手机类宝义 |
1、交流工具接口
interface CommTools{
void comm();
}
2、播放器接口
interface MediaPlayer{
void play();
}
|
public class SmartPhone implements CommTools, MediaPlayer{ //从CommTools中继承 public void comm(){ System.out.println("打电话"); } //从MediaPlayer中继承 public void play(){ System.out.println("听歌曲"); } } |
示例 |
public class Outer1{
private int size;
public class Inner{
public void doStuff(){
size++;
}
}
public void testTheInner(){
Inner i = new Inner();
i.doStuff();
}
}
|
捕获异常(数组越界、除数为零) |