关于继承 和 继承! 我在父类中定义:int age = Integer.parseInt(JOptionPane.showInputDialog("Iput the age:"));在子类中:怎样去调用这个父类中的age,并且判断它的大小 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这太不清楚了我这样用可以么?if (super.age <= 12) 只要你在子类中,没有定义age,可以用this.age得到父类的age this好象是得到子类本身的吧super才是得到父类的域吧这。。... 是不是这样int age = Integer.parseInt(JOptionPane.showInputDialog("Iput the age:"));public int returnAge(){ return age;}在子类中调用这个函数获得值 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!"); I'm a littlestudent.I'm young!........ 不知道你的这段干啥地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()写吧,你试试看 比我还菜啊,我刚看思想呢。 HomeWork6 hm = new HomeWork6(); hm.setAge(); if(age<=12)....... Java中如何将键值对为等号(=)的数据转换为JSON? 关于ResultSet的问题 a href 的submit 提交(他提交后给本页面不能得到equest.getparameter("startdate") 关于两种输入输出流的区别问题 按姓氏笔画排序在程序中是怎么实现的? 关于implements的问题 为什么实现事件机制时都需要一个List 求助,关于java中文件的读取。 求java网络及多线程编程的电子书 问一个简单问题,String s=""; 和语句 String s=null;有何不同 i = i++的问题 求救!
if (super.age <= 12)
super才是得到父类的域吧
这。。...
int age = Integer.parseInt(JOptionPane.showInputDialog("Iput the age:"));
public int returnAge(){
return age;
}
在子类中调用这个函数获得值
这到底错在哪里?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!");
........
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()写吧,你试试看
HomeWork6 hm = new HomeWork6();
hm.setAge();
if(age<=12)
.......