⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app9_7.java

📁 JAVA 2面向对象程序设计(随书范例程序)7-9.rar.rar
💻 JAVA
字号:
// app9_7, 通过父类变量cir调用show() method
class CCircle    // 父类CCircle
{
   protected double radius;
   protected static double pi=3.14;
   
   public CCircle(double r){
      radius=r;
   }
   public void show(){
      System.out.println("radius="+radius);
   }
}   

class CCoin extends CCircle  // 子类CCircle
{
   private int value;
   
   public CCoin(double r,int v){
      super(r);
      value=v;
   }
   public void show(){
      System.out.println("radius= "+radius+", value= "+value);
   }
   public void showValue(){
      System.out.println("value= "+value);
   }   
}

class app9_7
{
   public static void main(String args[]){
      CCircle cir=new CCoin(2.0,5);  // 声明父类变量cir,并将它指向对象
      cir.show();   // 利用父类变量cir调用show() method
   // cir.showValue();
   }
}

⌨️ 快捷键说明

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