public class P309 {
String subName;
int salary;
int totalBooks;
public P309(String subName,int totalBooks) {
this.subName=subName;
this.totalBooks=totalBooks;
}
void calculateHrs(){
salary=this.totalBooks*2;
}
public static void main(String[] args) {
}
}
class Science{
Science(){
P309 good = new P309("科学",10);
good.calculateHrs();
System.out.println(good.subName+"学科的总时数是"+good.salary);
}
}
class Arts{
Arts(){
P309 good = new P309("艺术",14);
good.calculateHrs();
System.out.println(good.subName+"学科的总时数是"+good.salary);
}
}
我现在要在P309中调用 Science() 和 Arts() 怎么调?.
在线等。...
----------------解决方案--------------------------------------------------------
在main方法中
new Science();
new Arts();
----------------解决方案--------------------------------------------------------
恩 先谢谢楼上了。。
可我这题目要重新定义个..
**** ***** = new Science();
这种格式。。...前面怎么弄?`=。=
----------------解决方案--------------------------------------------------------
知道哒哄声。..
在线等 .....
谢谢老。`
----------------解决方案--------------------------------------------------------
你可以用它的父类的类型或它自身的类型声明一个引用去指向这个对象
Object a=new Science();
或Science a=new Science();
不过你到底要干什么啊?
----------------解决方案--------------------------------------------------------
你也可以将 p309设置成Science() 和 Arts() 的内类 !!
----------------解决方案--------------------------------------------------------
看不懂
----------------解决方案--------------------------------------------------------
你也可以将 p309设置成Science() 和 Arts() 的内类 !!
恩 谢谢`
----------------解决方案--------------------------------------------------------