编程语言
首页 > 编程语言> > javaSE-多态

javaSE-多态

作者:互联网

目录

instanceof关键字

https://www.cnblogs.com/huachuantingyumian/p/16207004.html

final关键字

public final class A{

}
public final void a()
final int a = 10;//不允许修改值
final String s = "string";//不允许指向其他对象

抽象类和抽象方法

public abstract class A {
    public abstract void a();
}
public abstract class A {

    public abstract void a();

    public void a1()
    {
        System.out.println("a1");
    }
}
public class A1 extends A{
    @Override
    public void a() {

    }
}

public abstract class A1 extends A{

}
A a = new A() {
            @Override
            public void a() {
                
            }
        };
public abstract class A {
    public abstract void a();
}

public class A1 extends A{

    @Override
    public void a() {
        System.out.println("a");
    }

}

    public static void main(String[] args) {

        A a = new A1();
        a.a();
        A1 a1 = (A1) a;
        a1.a();

    }

接口

public interface A{
	int a = 10;
	void A();
}
public interface A{
	default void A(){
	
	};
}
public interface Eat {
    void eat();
}

public interface Drink {
    void drink();
}

public class InterfaceTest implements Eat, Drink {
    @Override
    public void eat() {
        System.out.println("eat");
    }

    @Override
    public void drink() {
        System.out.println("drink");
    }
}


public static void main(String[] args) {
        Eat eat = new InterfaceTest();
        eat.eat();
        Drink drink = new InterfaceTest();
        drink.drink();
    }

//eat
//drink
    public static void main(String[] args) {
        Eat eat = new InterfaceTest();
        eat.eat();
        InterfaceTest interfaceTest = (InterfaceTest) eat;
        interfaceTest.eat();
    }

//eat
//eat

标签:关键字,void,抽象类,多态,eat,public,javaSE,final
来源: https://www.cnblogs.com/huachuantingyumian/p/16211481.html