java中的接口一些知识点———— 代码

一 ; 
nterface Shape {

    public abstract void draw();
//    default  public void func(){
//
//    }
}

class  Cycle implements  Shape{
    public  void draw(){
        System.out.println(" ⭕");
    }
}
class  Flower implements  Shape{
    public  void draw(){
        System.out.println(" ❀");
    }
}

public class TestLong {

    public static  void drawMap(Shape shape){
        shape.draw();
    }

    public static void main (String[] args){
        Shape shape = new Flower();
        shape.draw();
        Shape shape1 = new Cycle();
        shape1.draw();
        Flower flower = new Flower();
        drawMap(flower);
    }


}
二;
interface  IA{
    void  func();

}

abstract class A implements  IA{
    public  void fun(){
        System.out.println("4444");
    }
}
interface  IB extends  IA{
    void fun2();
}

class  C implements  IB{
    public C() {
        super();
    }

    @Override
    public void func() {

    }

    @Override
    public void fun2() {

    }
}
interface  ID{
    public  void fun3();
}
interface  IC extends  IB ,ID{
    @Override
    void func();

    @Override
    void fun2();

    @Override
    void fun3();
}

class  Animal {
    protected String name ;

    public  Animal (String name){
        this.name = name;
    }
}
interface  IFlying{
    void fly();

}
interface  IRunnig {
    void run();
}
interface  ISwimming{
    void  swim();
}

class  Cat  extends  Animal implements  IRunnig {
    public Cat(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + " 正在跑");
    }
}
class Fish extends  Animal implements  ISwimming{
    public  Fish(String name){
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(this.name + " 正在用尾巴游泳");
    }
}
class  Forg extends  Animal implements  IRunnig, ISwimming{
    public Forg(String name){
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(this.name + " 正在游泳" );
    }

    @Override
    public void run() {
        System.out.println(this.name + " 正在跑步");
    }
}
class  RoBot implements  IRunnig{
    @Override
    public void run() {
        System.out.println("机器人再跑");
    }
}
public class TestDemo {
    public static void function1(IRunnig iRunnig){
        iRunnig.run();
    }
    public static void function2(ISwimming iSwimming) {
        iSwimming.swim();
    }
    public static void function3(IFlying iFlying){
        iFlying.fly();
    }
    public static void main (String[] args){
        function2(new Fish("HAHHAHA"));

    }
    public static void main1 (String[] args){
    Animal animal = new Fish("HAHHAHA");
    ISwimming iSwimming = new Fish("HHHHHHHH");
    }
}
三 ;
class  Student implements Comparable<Student >{
    public int age;
    public  String name;
    public  int score;


    public Student(int age, String name, int score) { // alt + insert
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if (this.age < o.age){
            return  -1;
        }else if(this.age > o.age){
            return 1;
        }else {
            return 0;
        }
    }
}
public class TestCheng {
    public static  void main3 (String[] args){
        Student student1 = new Student(10,"lallal",65);
        Student student2 = new Student(34,"laal",63);

        if (student1.compareTo(student2) > 0){
            System.out.println("student1 > student2");
        }else if(student1.compareTo(student2) < 0){
            System.out.println("student1 < student2");
        }else {
            System.out.println("student1 == student2");
        }

    }
    public static void main (String[] args){
        Student[] students = new Student[3];
        students[0] = new Student(10,"lallal",65);
        students[1] = new Student(34,"laal",63);
        students[2] = new Student(20,"lal",85);
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void main1 (String[] args){
        int[] array  = {1,2,3,3,4,2,4,35,45,4};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
四;
class Money implements  Cloneable{
    public  double money = 34.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class  Person implements  Cloneable{
    public String name = " lalal";
    public Money  m = new Money();

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person person = (Person) super .clone();
         person.m = (Money) person.m.clone();
         return  person;
        //return super.clone();
    }

}
public class TestXi {
    public static void main (String[] args)throws CloneNotSupportedException {
        Person person = new Person();
        Person person1 = (Person) person.clone();
        System.out.println(person.m.money);
        System.out.println(person1.m.money);
        System.out.println("============");
        person1.m.money = 99.99;
        System.out.println(person.m.money);
        System.out.println(person1.m.money);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值