标签:end dem 方法 java shutdown 重写 int pex child
多态
package day8; public abstract class Instrument { public abstract void play(); }
package day8; public class Piano extends Instrument{ @Override public void play() { // TODO Auto-generated method stub System.out.println("yueguangqu"); } }
package day8; public class Violin extends Instrument{ public void play() { // TODO Auto-generated method stub System.out.println("风吹麦浪"); } }
package day8; //多态类题型: //使用继承 //子类重写父类的方法 //父类引用子类对象 public class Artist { // public void make(Piano piano){ // piano.play(); // } // public void make(Violin violin){ // violin.play(); // } public void make(Instrument instrument){ instrument.play(); } }
package day8; public class Test { public static void main(String[] args) { Artist artist = new Artist(); Piano piano = new Piano(); artist.make(piano); Violin violin = new Violin(); artist.make(violin); } }
================================================================================================================
接口
package day83; public interface InterfaceDemo { //1:接口不能被实例化 //2:接口里的方法默认都是public类型的抽象方法 //所有public abstract修饰可以忽略 //3:类是单继承,但是类可以实现多个接口 //4:在接口里定义的属性都是public类型的静态常量 //public static final都是可以省略的 //5:接口可以继承多个接口,可以得到父级接口里所有的属性和方法 public abstract void showName(); public static final int AGE = 10; }
package day83; public interface InterfaceDemo2 { void showName2(); }
package day83; public abstract class Father { public abstract void showFatherName(); }
package day83; public abstract class Father2 { public abstract void showFatherName2(); }
package day83; public interface ChildInterface extends InterfaceDemo,InterfaceDemo2{ }
package day83; import java.nio.channels.ShutdownChannelGroupException; public class Test extends Father implements InterfaceDemo,InterfaceDemo2{ public static void main(String[] args) { // Interface demo = new InterfaceDemo();是不可以的 Test test = new Test(); } @Override public void showName() { // TODO Auto-generated method stub } @Override public void showName2() { // TODO Auto-generated method stub } @Override public void showFatherName() { // TODO Auto-generated method stub } }
=======================================================================================================
综合类
package day86; public class A4Paper implements Paper{ @Override public void pageSize() { System.out.println("使用A4纸!"); } }
package day86; public class B5Paper implements Paper{ @Override public void pageSize() { System.out.println("使用B5纸!"); } }
package day86; public class BlackInk implements Ink{ @Override public void inkColor() { System.out.println("使用黑白墨!"); } }
package day86; public class ColorInk implements Ink{ @Override public void inkColor() { System.out.println("使用彩墨!"); } }
package day86; public interface Ink { void inkColor(); }
package day86; public interface Paper { void pageSize(); }
package day86; public class Printer { public Ink ink; public Paper paper; public void print(String content){ ink.inkColor(); paper.pageSize(); System.out.println(content); } public static void main(String[] args) { Printer printer = new Printer(); printer.ink = new BlackInk(); printer.paper = new A4Paper(); printer.print("我是打印内容!"); } }
标签:end dem 方法 java shutdown 重写 int pex child
原文地址:http://www.cnblogs.com/haloxinghong/p/7425552.html