Java 抽象类
、
1 package com.qugeng.jdk; 2 3 public class MethodDemo { 4 public static void main(String[] args) { 5 AbsDemo a = new AbsDemo(); 6 a.say(); 7 a.print(); 8 } 9 } 10 11 abstract class Abs{ 12 private int age; 13 public void tell(){ 14 } 15 public abstract void say(); 16 public abstract void print(); 17 } 18 19 /** 20 * 子类必须重写父类的方法 21 * @author Administrator 22 * 23 */ 24 class AbsDemo extends Abs 25 { 26 public void say() { 27 } 28 public void print(){ 29 30 } 31 } 32
1 package com.qugeng.jdk; 2 3 public class MethodDemo { 4 public static void main(String[] args) { 5 A a = new A(); 6 a.tell(); 7 System.out.println(); 8 } 9 } 10 11 interface Inter2 12 { 13 public abstract void say(); 14 15 } 16 17 abstract class Abs1{ 18 public abstract void print(); 19 } 20 21 interface Inter1{ 22 23 public static final int AGE = 100; 24 public abstract void tell(); 25 } 26 27 28 class A extends Abs1 implements Inter1,Inter2{ 29 public void tell(){ 30 31 } 32 public void say() 33 { 34 35 } 36 public void print() 37 { 38 39 } 40 }