Question: Java Exam QUESTION 1 What is wrong in the following code? class Y { int i ; public Y ( int i ) { i

Java Exam
QUESTION 1
What is wrong in the following code?
class Y{
int i;
public Y(int i){
i= this. i;
}
}
public class
public static void main(String[] args){
Yy= new Y(2);
}
}
A. The program has a compilation error because Y does not have a default constructor.
B. The program has a compilation error because Y does not have a constructor with an int
argument.
C. The definition of the constructor should be i= this. i;
D. Constructor of Y can not take argument named i, as the class has a member named i.
QUESTION 2
Analyze the following code:
public class Test {
static double radius;
public static void main(String[] args){
final double ?PI=3.15169;
double area = radius * radius *?PI ;
System.out.printIn("Area is "+ area);
}
}
A. The program has compile errors because the variable radius is not initialized.
B. The program has a compile error because a constant ?PI is defined inside a method.
C. The program has no compile errors but will get a runtime error because radius is not
initialized.
D. The program compiles and runs fine but the area will be always 0.
 Java Exam QUESTION 1 What is wrong in the following code?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!