Professional Documents
Culture Documents
OOP
1. Create an Encapsulated class Point class with x and y as data members. Create two
constructors and a function to move the point.
In the runner create an array of point objects of size 10. Initialize first five objects
using default constructor and others using argument constructor.
Solution code
class point{
private double x;
private double y;
// constructor
public point(){
x = 1.7;
y = 2.5;
}
// argumented
public point (double a, double b){
x= a;
y = b;
}
// setters
}
void setY(double a){
y = a;
// getters
double getX(){
return x;
}
double getY(){
return y;
}
void display(){
System.out.println("THE VALUE OF X IS"+ x);
System.out.println("THE VALUE OF Y IS"+ y);
}
}
RUNNER FILE:
public class runnerpoint{
public static void main(String[] args) {
arr[0]=new point();
arr[1]=new point();
arr[2]=new point();
arr[3]=new point();
arr[4]=new point();
for(int i = 0; i<5;i++){
arr[i].setY(19);
}
System.out.println(" \nDisplay1\n");
System.out.println(" \nDisplay2\n");
for(int i = 0; i<5;i++){
arr[i].display();
}
}
}