zoukankan      html  css  js  c++  java
  • 关于接口和接口中多肽问题的实例

    /**
     * 关于接口和接口中多肽问题的实例
     * 
     * @author iflytek
     * 
     */
    interface Singer {
    	public void sing();
    
    	public void sleep();
    }
    
    interface Painter {
    	public void paint();
    
    	public void eat();
    }
    
    class Student implements Singer {
    	private String name;
    
    	Student(String name) {
    		this.name = name;
    	}
    
    	public void study() {
    		System.out.println("studying......");
    	}
    
    	@Override
    	public void sing() {
    		System.out.println("student sing......");
    
    	}
    
    	@Override
    	public void sleep() {
    		System.out.println("student sleep......");
    
    	}
    }
    
    class Teacher implements Singer, Painter {
    	private String name;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	Teacher(String name) {
    		this.name = name;
    	}
    
    	public void teach() {
    		System.out.println("teacher teach......");
    	}
    
    	@Override
    	public void paint() {
    		System.out.println("teacher paint......");
    
    	}
    
    	@Override
    	public void eat() {
    		System.out.println("teacher eat......");
    
    	}
    
    	@Override
    	public void sing() {
    		System.out.println("teacher sing......");
    
    	}
    
    	@Override
    	public void sleep() {
    		System.out.println("teacher sleep......");
    
    	}
    
    }
    
    public class TestSinger {
    	public static void main(String[] args) {
    		Singer s1 = new Student("le");
    		s1.sing();
    		Singer s2 = new Teacher("steven");
    		s2.sing();
    		s2.sleep();
    		Painter p1 = (Painter) s2;
    		p1.paint();
    		p1.eat();
    		System.out.println((Painter) s2 instanceof Teacher);
    		System.out.println(s2 instanceof Teacher);
    		System.out.println(p1 instanceof Teacher);
    	}
    }
    

  • 相关阅读:
    Redis 集群方案
    Redis集群搭建
    Java并发问题--乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
    为什么分布式一定要有Redis?
    如何准备Java初级和高级的技术面试
    SpringBoot自动配置原理
    高德地图-- 云图管理台
    GeoJSON格式规范说明
    webGis概念
    npm压缩js文件
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671584.html
Copyright © 2011-2022 走看看