Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the complete working solutions and accurate answers to these questions. T

ID: 3865651 • Letter: I

Question

I need the complete working solutions and accurate answers to these questions. Thanks

Consider the following code: public class Point { private int x: private int y: public Point() { this.x = 0: this y= 0: } //Point } public class PointRunner { public static void main(String[] args) { Point p = new Point(): p middot x = 2: P middot y = 2: System.out printf("(%d, %d ", p.x, p. y): }//main } What is the output after running main()? (a) "(0, 0)" (b) "(2, 2)" (c) "(null, null)" (d) Compile-time error (e) Runtime error

Explanation / Answer

Answer : Compile-time error

because in the program we declared 'x' and 'y' variables as "private". So the x and y are not accsesssed by the main() method . the result is undeclared 'x' and 'y'

OUTPUT :

PointRunner.java:1: error: class Point is public, should be declared in a file named Point.java
public class Point{
^
PointRunner.java:13: error: x has private access in Point
p.x =2 ;
^
PointRunner.java:14: error: y has private access in Point
p.y = 2;
^
PointRunner.java:15: error: x has private access in Point
System.out.printf("(%d %d) ",p.x , p.y);
^
PointRunner.java:15: error: y has private access in Point
System.out.printf("(%d %d) ",p.x , p.y);
^

##################################################################

=> If you change the your program as like below program you can get (2, 2) output

Correct program :

class Point{

int x;
int y;
public Point(){
this.x = 0;
this.y = 0;
}//point
}

public class PointRunner{
public static void main(String[] args){
Point p = new Point();
p.x =2 ;
p.y = 2;
System.out.printf("(%d %d) ",p.x , p.y);
}//main
}