[ testcartesianpoint.java ]
import java.io.*;import graphics.*;
class testcartesianpoint
{
public static void main(String args[])
{
CartesianPoint obj;
obj=new CartesianPoint(10); //CONSTRUCTOR WITH ONE PARAMETER
obj.display();
obj=new CartesianPoint(10,20); //CONSTRUCTOR WITH TWO PARAMETER
obj.display();
obj.move(30); //MOVE FUNCTION WITH ONE ARGUMENT
obj.display();
obj.move(30,40); //MOVE FUNCTION WITH TWO ARGUMENT
obj.display();
}
}
[ graphics.java ]
(save it in graphics folder)
(save it in graphics folder)
package graphics;
public class CartesianPoint
{
double x,y;
public CartesianPoint()
{
}
public CartesianPoint(double x)
{
System.out.println("CONSTRUCTOR WTIH ONE PARAMETER");
this.x=x;
this.y=x;
}
public CartesianPoint(double x,double y)
{
System.out.println("CONSTRUCTOR WTIH TWO PARAMETER");
this.x=x;
this.y=y;
}
public double getx()
{
return x;
}
public double gety()
{
return y;
}
public void move(double x,double y)
{
System.out.println("MOVE METHOD WTIH ONE PARAMETER");
this.x=x;
this.y=y;
}
public void move(double x)
{
System.out.println("MOVE METHOD WTIH TWO PARAMETER");
this.x=x;
this.y=x;
}
public void display()
{
System.out.println("Value of x : " + x);
System.out.println("Value of y : " + y);
}
}
GoTo Command Prompt(Win + R)
ReplyDeleteHOW TO COMPILE
javac c:\yourdir\graphics\graphics.java
javac c:\yourdir\testcartesianpoint.java
HOW TO EXECUTE
java c:\yourdir\testcartesianpoint