/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package metody;
/**
*
* @author Marcin
*/
public class Metody {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Punkt punkt = new Punkt();
Punkt nPunkt = new Punkt();
Punkt trzeciPunkt = new Punkt();
punkt.setX(100);
punkt.setY(100);
nPunkt.setXY(1, 2);
punkt.showXY();
System.out.println("\nWspołrzędne drugiego punktu: \nx = "+nPunkt.getX()
+" y = "+nPunkt.getY());
trzeciPunkt.setXY(punkt);
System.out.println(trzeciPunkt.showXY());//dlaczego to nie działa?, bez tej lini wszystko jest ok
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package metody;
/**
*
* @author Marcin
*/
class Punkt {
int x;
int y;
void setX(int wspX){
x = wspX;
}
void setY(int wspY){
y = wspY;
}
void setXY(int wspX, int wspY){
x = wspX;
y = wspY;
}
//obiekt jako argument metody
void setXY(Punkt punkt){
x = punkt.x;
y = punkt.y;
}
int getX(){
return x;
}
int getY(){
return y;
}
void showXY(){
System.out.print("Wsp x: "+x);
System.out.print("\nWsp y: "+y);
}
}
Debugger pokazuje, że trzeciPunkt otrzymał kopie obiektu punkt, to dlaczego nie mogę ich wyświetlić?