Implementasi OOP java untuk titik
class titik
{
private int x;
private int y;
titik()
{
x = 0;
y = 0;
}
titik(int xp, int yp)
{
x = xp;
y = yp;
}
public void setx(int xp)
{
x = xp;
}
public void sety(int yp)
{
y = yp;
}
public int getx()
{
return x;
}
public int gety()
{
return y;
}
}
class Main
{
public static void main(String[] args) {
titik t1 = new titik();
titik t2 = new titik(11,9);
t1.setx(18);
t1.sety(28);
System.out.println("T1 : nilai x : " + t1.getx());
System.out.println("T1 : nilai y : " + t1.gety());
System.out.println("T2 : nilai x : " + t2.getx());
System.out.println("T2 : nilai y : " + t2.gety());
}
}
Komentar
Posting Komentar