我在父类中定义:
int age = Integer.parseInt(JOptionPane.showInputDialog("Iput the age:"));在子类中:
怎样去调用这个父类中的age,并且判断它的大小

解决方案 »

  1.   

    这太不清楚了我这样用可以么?
    if (super.age <= 12)
      

  2.   

    只要你在子类中,没有定义age,可以用this.age得到父类的age
      

  3.   

    this好象是得到子类本身的吧
    super才是得到父类的域吧
    这。。...
      

  4.   

    是不是这样
    int age = Integer.parseInt(JOptionPane.showInputDialog("Iput the age:"));
    public int returnAge(){
       
        return age;
    }
    在子类中调用这个函数获得值
      

  5.   

    5555555555
    这到底错在哪里?import javax.swing.JOptionPane;public class HomeWork6
    {
    static int age;

    public void setAge()
    {
    age = Integer.parseInt(JOptionPane.showInputDialog("Please input the age:"));
    }

    public int returnAge()
    {
    return age;
    }

    public static void main(String args[])
        {
         HomeWork6 hm = new HomeWork6();
         hm.setAge();
        }
    }class LittleStudent extends HomeWork6
    {
    HmoeWork6 hm = new HomeWork6();
    if (hm.returnAge <= 12)
    System.out.println("I'm a littlestudent.I'm young!");
      

  6.   

    I'm a littlestudent.I'm young!
    ........
      

  7.   

    不知道你的这段干啥地
    public static void main(String args[])
        {
        HomeWork6 hm = new HomeWork6();
        hm.setAge();
        }class LittleStudent extends HomeWork6
    {
    HmoeWork6 hm = new HomeWork6();
    if (hm.returnAge <= 12)
    System.out.println("I'm a littlestudent.I'm young!");
    这2个合并一下不行么?
    再有就是你那个hm.returnAge调用的时候要hm.returnAge()写吧,你试试看
      

  8.   

    比我还菜啊,我刚看思想呢。
      HomeWork6 hm = new HomeWork6();
        hm.setAge();
      if(age<=12)
    .......