Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Generative Artificial Intelligence For Project Management With Aws

Authors: Timothy Krimmel

1st Edition

B0CQV9KWB8, 979-8872627197

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago