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);
     }
    }

  • 相关阅读:
    Codeforces 877 C. Slava and tanks
    Codeforces 877 D. Olya and Energy Drinks
    2017 10.25 NOIP模拟赛
    2017 国庆湖南 Day1
    UVA 12113 Overlapping Squares
    学大伟业 国庆Day2
    51nod 1629 B君的圆锥
    51nod 1381 硬币游戏
    [JSOI2010]满汉全席
    学大伟业 2017 国庆 Day1
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/3020703.html
Copyright © 2011-2022 走看看