Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code

public class Triangle {
static double area;
int b = 2, h = 3;

public static void main(String[] args) {
double p, b, h; // line n1
if (area == 0) {
b = 3;
h = 4;
p = 0.5;
}
area = p * b * h; // line n2
System.out.println("Area is " + area);
}
}

What is the result?

  : You have been given below code
1. Area is 6.0
2. Area is 3.0
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails at line n2




Correct Answer : Get Lastest Questions and Answer :








Question : Given the code fragment:

public class Test {
public static void main(String[] args) {
// line n1
switch (x) {
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;

}
}
}

Which three code fragments can be independently inserted at line nl to enable the code to print one?

A. Byte x = 1;
B. short x = 1;
C. String x = "1";
D. Long x = 1;
E. Double x = 1;
F. Integer x = new Integer ("1");

  : Given the code fragment:
1. A,B,F
2. C,D,E
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E,F


Correct Answer : Get Lastest Questions and Answer :
Explanation:







Question : You have been given below code, what would be printed when you run it.

public class App {
public static void main(String[] args) {
Boolean[] bool = new Boolean[2];
bool[0] = new Boolean(Boolean.parseBoolean("true"));
bool[1] = new Boolean(null);
System.out.println(bool[0] + " " + bool[1]);
}
}



  : You have been given below code, what would be printed when you run it.
1. True false
2. True null
3. Access Mostly Uused Products by 50000+ Subscribers

4. A NullPointerException is thrown at runtime



Correct Answer : Get Lastest Questions and Answer :

Explanation:




Related Questions


Question : Given the for loop construct:

for ( expr1 ; expr2 ; expr3 ) {
statement;
}

Which two statements are true?
A. This is not the only valid for loop construct; there exits another form of for loop constructor.
B. The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop begin.
C. When expr2 evaluates to false, the loop terminates. It is evaluated only after each iteration through the loop.
D. The expression expr3 must be present. It is evaluated after each iteration through the loop

 : Given the for loop construct:
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. A,C





Question : You have been given following code

class Overloading {
int x(double d) {
System.out.println("one");
return 0;
}

String x(double d) {
System.out.println("two");
return null;
}

double x(double d) {
System.out.println("three");
return 0.0;
}

public static void main(String[] args) {
new Overloading().x(4.0);
}
}

What is the result?

 : You have been given following code
1. One
2. Two
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails






Question : :You have been given following code

public class Test {
public static void main(String[] args) {
try {
String[] arr = new String[4];
arr[1] = "Unix";
arr[2] = "Linux";
arr[3] = "Solarios";
for (String var : arr) {
System.out.print(var + " ");
}
} catch (Exception e) {
System.out.print(e.getClass());
}
}
}

What is the result?

 : :You have been given following code
1. Unix Linux Solaris
2. Null Unix Linux Solaris
3. Access Mostly Uused Products by 50000+ Subscribers
4. Class java.lang.NullPointerException




Question : Which of the following exception will be thrown due to the statement given here?
int array[]= new int[-2];


 : Which of the following exception will be thrown due to the statement given here?
1. NullPointerException
2. NegativeArraySizeException
3. Access Mostly Uused Products by 50000+ Subscribers
4. IndexOutOfBoundsException
5. This statement does not cause any exception




Question : You have been given following code snippet

float x = 22.00f % 3.00f;
int y = 22 % 3;
System.out.print(x + ", " + y);

What is the result?


 : You have been given following code snippet
1. 1.0, 1
2. 1.0f, 1
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. An exception is thrown at runtime




Question : You have been given following code

package p1;

public class Test {
static double dvalue;
static Test ref;

public static void main(String[] args) {
System.out.println(ref);
System.out.println(dvalue);
}
}

What is the result?


 : You have been given following code
1. p1.Test.class 0.0
2. 0.000000
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. A NullPointerException is thrown at runtime