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

📄 testsuper.java

📁 这是一张java应用教程的随书光盘
💻 JAVA
字号:
class Animal {
	 String hostname;
     String color;
	 int age;
     float weight;
     Animal(String s, float w){
    	this.hostname=s ;  this.weight = w;
	 	System.out.println("My hostname is "+hostname+"\n" + "My weight is  "+weight);
    	}
    void setAge(int i){
	   this.age = i;
	 	}
    void  setColor(String st) {
	   this.color=st;
	 	}
	void setHostname(String str){
	    this.hostname=str;
		}         
	public String getInfo() {
		return "hostname: "+ hostname + "\n" +"age: "+ age;
		}
	}

class Dog extends Animal{
	  float weight;
	  String hostname;
	  void setHostname(String host) {
	  	hostname=host;
	 	}
	 void setWeight(float g){
	 	weight = g;
	 	}
   	Dog( String s, float w, String c){
     	super(s,w);           //调用父类构造函数
     	color =c;
    	System.out.println("My weight is  "+super.weight); //调用父类被隐藏的变量
    	System.out.println(super.getInfo());  //调用父类被覆盖的方法
     	}
	public String getInfo() {
		return  "this.Hostname="+ hostname+ "  this.age="+ age+"   this.Color ="+ color  ;
		}
	}
class  superTest{
	public static void main(String args[]){
    	Dog bini = new Dog("pipi", 16.8f, "white");
    	bini.setAge(2);
    	bini.setColor("Black");
    	bini.setWeight(10.5f);
    	bini.setHostname("Lucky");       
		System.out.println("this.weight="+bini.weight); //调用子类隐藏的变量()
    	System.out.println(bini.getInfo());          //调用子类覆盖的方法                  
		}
	}

⌨️ 快捷键说明

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