class A{
  String str;
  private int n = 123456;
  public A(String str){
    this.str = str;
  }
  public int getn(){
    return n;
  }
}class B extends A{
  float x;
  public B(String str, float x){
    super.str = str;
    this.x = x;
  }
}public class Class1{
  boolean bool = true;
  B b;
  public static void main(String[] args){
    b = new b('java', 12345.6);
    System.println("str = " + b.str);
    System.println("n   = " + b.getn());
    System.println("x   = " + b.x);
    System.println("bool = " + b.bool);  }
}

解决方案 »

  1.   

    class A {
      public String str;
      private int n = 123456;
      public A(){  }  public A(String strA) {
        str = strA;
      }  public int getn() {
        return n;
      }
    };class B
        extends A {
      float x;
      public B(String strB, float fValue) {
        str = strB;
        x = fValue;
      }
    };class Calss1 {
      public static void main(String[] args) {
        boolean bool = true;
        float dddd = 12345.6f;
        B b = new B("java", dddd);
        System.out.println("str=" + b.str + ";n=" + b.getn() + ";x=" + b.x +
                           ";bool:=" + bool);
      }
    }
      

  2.   

    class A{
    public String str;
    private int n=123456;
    public A(){}
    public A(String strA){
    str=strA;
    }
    public int getn(){
    return n;
    }
    }
    class B extends A{
    float x;
    public B(String strB,float xB){
    str=strB;
    x=xB;
    }
    }
    public class Class1{
    static boolean bool=true;
    public static void main(String args[]){
    B b=new B("java",12345.6f);
    System.out.println("str: "+b.str);
    System.out.println("n: "+b.getn());
    System.out.println("x: "+b.x);
    System.out.println("bool: "+bool);
    }
    }