能不能帮我详细解释一下?先谢谢了!
public class Pixel{
int x;
int y;
void init (int x,int y){
this.x = x;
this.y=y;
}
public static void main(String args [] ){
Pixel p = new Pixel();
p.int(4,3);
}
}
能不能帮我详细解释一下?先谢谢了!
public class Pixel{
int x;
int y;
void init (int x,int y){
this.x = x;
this.y=y;
}
public static void main(String args [] ){
Pixel p = new Pixel();
p.int(4,3);
}
}
public class Pixel{
int x; //类属性
int y;
void init (int x,int y){ //类方法
this.x = x; //将形参传给属性
this.y=y;
}
public static void main(String args [] ){ //程序入口
Pixel p = new Pixel(); //实例化一个Pixel对象,并将其引用赋给p
p.init(4,3); //调用init()方法,并将值传入。。。
}
}
突然有个好玩的想法。。。
程序员就像是位母亲。。。当写类的时候就相当于老妈10月怀胎。。。在这里就是
[CODE]public class Pixel{
int x;
int y;
void init (int x,int y){
this.x = x;
this.y=y;
}[/CODE]
实例化此类就是终于把孩子生出来了。。。new Pixel().给孩子取个名字吧 Pixel p....
妈妈想让孩子做点什么,就叫孩子的名字.要做的事情。。。p.init(4,3);孩子很听话就照做了。。。
最后这孩子的使命就完成了。。。等待死神到来(垃圾回收)。。。