package ;
//JAVA继承是单继承,一个类只能有一个父类,所以接口可以看成是继承的一种补充
class Monkey{
int age;
String name;
public void jump(){
System.out.println("猴子跳");
}
}
interface Fish{
public void swimming();
}
interface Bird{
public void fly();
}
class LittleMonkey extends Monkey implements Fish,Bird{
@Override
public void fly() {
// TODO Auto-generated method stub
System.out.println("小鸟飞");
}
@Override
public void swimming() {
// TODO Auto-generated method stub
System.out.println("鱼游泳");
}
}
public class Demo1 {
public static void main(String[] args) {
LittleMonkey lm=new LittleMonkey();
lm.jump();
lm.fly();
lm.swimming();
}
}
package ;
//final的用法
//1 不希望某个变量的值被修改(有final的变量必须附初始值,不然编译报错)
//2 不希望父类的某个方法被子类覆盖
//3 不希望某个类被继承
class A{
int a;
final double b=3.1415;
public void c(){
System.out.println("a="+a+"可以修改");
}
final public void d(){
System.out.println("b="+b+"不能修改");
}
}
class B extends A{
public B(){
a++;
//当写上b++时,报错,说明b的值不能改
//b++;
}
}
public class Demo2 {
public static void main(String[] args) {
B b=new B();
b.c();
b.d();
}
}