code:class atom{
int i;
int j;
void atom(int i, int j){
this.i =i;
this.j = j;
}
}class list{
atom [] element;
String name;
viod list(atom[] element, String name){
this.element = element;
this.name = name;
}
}
public class Main{
public static void main(String args[]){
atom [] tmp;
tmp[0] = new atom(1,2);
tmp[1] = new atom(2,3);
list ls = new list(tmp, "haha");
}
}这样对么?好像数组拷贝有问题.
还有一个问题是:main() 是static的,所以要求在main()里面调用的函数也要是static的,搞得程序运行很慢,有什么变通的方法??
int i;
int j;
void atom(int i, int j){
this.i =i;
this.j = j;
}
}class list{
atom [] element;
String name;
viod list(atom[] element, String name){
this.element = element;
this.name = name;
}
}
public class Main{
public static void main(String args[]){
atom [] tmp;
tmp[0] = new atom(1,2);
tmp[1] = new atom(2,3);
list ls = new list(tmp, "haha");
}
}这样对么?好像数组拷贝有问题.
还有一个问题是:main() 是static的,所以要求在main()里面调用的函数也要是static的,搞得程序运行很慢,有什么变通的方法??
public atom(atom a) {
atom at=new atom(a.i,a.j);
}len=element.length;
this.element=new atom[len];
for(int i=0;i<len;i++) {
this.element[i]=new atom(element[i]);
}
考级与实际项目完全是两回事,项目中不允许写很多考试中出现的的代码,比如x++x++++x什么,写给谁来读呢,想知道它怎么执行,用反编译(或反汇编)看看就知道了
class Atom {
int i;
int j; Atom(int i, int j) { //去掉void,声明为一个构造函数
this.i = i;
this.j = j;
}
}class UrList {
Atom[] element;
String name; UrList(Atom[] element, String name) { //去掉void,声明为一个构造函数
this.element = element;
this.name = name;
}
}public class Main {
public static void main(String[] args) {
Atom[] tmp = new Atom[2]; //需要初始化后才能引用
tmp[0] = new Atom(1, 2);
tmp[1] = new Atom(2, 3);
UrList ls = new UrList(tmp, "haha");
System.out.println(ls);
}
}
class atom{
int i;
String j; public atom(int i, String j){
this.i =i;
this.j = j;
}
}String 是对象,能直接用等于么?如果不,那用什么?