hhhhhhhhhh
wake and see
package com.hiyo.HighClass;
class A {
public String ID = "CLASS A";
private String name ;
private float price ;
public A(String name,float price){
this.setName(name);
this.setPrice(price);
}//父类中带参数的构造方法
public String getName(){
return this.name ;
}
public float getPrice(){
return this.price ;
}
public void setName(String name) {
this.name = name ;
}
public void setPrice(float price){
this.price = price ;
}
public void print(){
System.out.println("这个是父类中的打印方法");
System.out.println(this.getName() + this.getPrice());
}
private void see(){
System.out.println("父类中的私有方法see");
}
public void watch() {
this.see();
}
}
class B extends A {
public B(String name, float price){
super(name,price);
}
//super()或者super(a,b)可以调用父类中的无参数和有参数的方法。
public String ID = "CLASS B";
public void print(){//覆写父类中的同名方法
System.out.println("这是子类覆写的方法");
System.out.println(this.getName() + this.getPrice());
}
public void see(){
System.out.println("子类中的SEE方法,访问default");
}
public void IDPrint() {
System.out.println(super.ID);
System.out.println(this.ID);
}
}
public class ExtendsDemo3 {
public static void main(String[] args ) {
A a = new B("a",5.0f) ;
a.print();//子类的print
A a1 = new A("b",6.0f) ;
a1.print(); //父类的print
B b = new B("x",7.0f) ;
b.watch();
b.IDPrint();
}
}
下面是一个Java的实例
package com.hiyo.HighClass;
class Array {
private int temp[] ;//定义整型数组,大小外部确定
private int foot ; //数组添加的角标
public Array(int len){//构造函数
if(len>0){
this.temp = new int[len];//根据传入的大小开辟空间
} else {
this.temp = new int[1];//最小又一个元素
}
}
public boolean add(int i) {
if(this.foot



