zoukankan      html  css  js  c++  java
  • 成员变量的隐藏和方法重写(Example5_3/Example5_4/Example5_5)

    class A{
     public double y=11.456789;
     public void f(){
      y=y+1;
      System.out.printf("y是double型的变量,y=%f\n",y);
     }
    }
    class B extends A{
     int y=0;
     public void g(){
      y=y+100;
      System.out.printf("y是int型的变量,y=%d\n",y);
     }
    }
    public class Example5_3{
     public static void main(String arg[]){
      B b=new B();
      b.y=200;
      b.g();
      b.f();
     }
    }

    class A{
     protected double x=8.0,y=0.888888;
     public void speak(){
      System.out.println("我喜欢NBA");
     }
     public void cry(){
      y=x+y;
      System.out.printf("y=%f\n",y);
     }
     
    }
    class B extends A{
     int y=100,z;
     public void speak(){
      z=2*y;
      System.out.println("I love This Game");
      System.out.printf("y=%d,z=%d",y,z);
     }
    }
    public class Example5_4{
     public static void main(String arg[]){
      B b=new B();
      b.cry();
      b.speak();
     }
    }

    class A{
     public int f(int x,int y){
      return x+y;
     }
    }
    class B extends A{
     public int f(byte x,int y){
      return x*y;
     }
    }
    public class Example5_5{
     public static void main(String arg[]){
      int z=0;
      B b=new B();
      z=b.f(10,10);
      System.out.println(z);
      z=b.f((byte)10,10);
      System.out.println(z);
     }
    }

  • 相关阅读:
    Nginx的启动、停止与重启
    用Java实现链表结构对象:单向无环链表
    java匿名内部类详解
    如何统计博客园的个人博客访问量
    Java 读写Properties配置文件
    java的枚举类型Enum解释
    接口测试框架1
    python几道简单的算法题
    很全的 Python 面试题
    有有面试
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/3020703.html
Copyright © 2011-2022 走看看