example3_11.java

来自「书中的例题」· Java 代码 · 共 35 行

JAVA
35
字号
/* 抽象类 */
abstract  class  生物      //生物类为抽象类
{
    public  abstract String 特征() ;
} 

class  植物  extends  生物   // 植物是生物的子类 
{ 
	String leaf;
    植物(String _leaf)
        {this.leaf=_leaf;}
    public String 特征()
	    {return leaf;	}
}

class  动物  extends  生物   // 动物是生物的子类 
{ 
	String mouth;
    动物(String _mouth)
        {this.mouth=_mouth;		}
    public String 特征()
	    {return mouth;}
}

public  class  Example3_11
 { 
	 public  static  void  main(String args[])
       {
		  植物 A = new 植物("叶");  
          System.out.println("植物的特征:"+A.特征()); 
		  动物 B = new 动物("嘴巴");
		  System.out.println("动物的特征:"+B.特征());         
		}
 } 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?