Premium

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



Question : You have been given below code

public class FieldInit {
char c;
boolean b;
float f;

void printAll() {
System.out.println("c = " + c);
System.out.println("c = " + b);
System.out.println("c = " + f);
}

public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}

What would be result ?

 : You have been given below code
1. c = null
b = false
f = 0.0F
2. c = 0
b = false
f = 0.0f
3. Access Mostly Uused Products by 50000+ Subscribers
b = true
f = 0.0
4. c =
b = false
f = 0.0




Correct Answer : Get Lastest Questions and Answer :







Question : You have been given following code

int a = 0;
a++;
System.out.println(a++);
System.out.println(a);

What would be the result ?

 : You have been given following code
1. 1

2. 0

3. Access Mostly Uused Products by 50000+ Subscribers

4. 2




Correct Answer : Get Lastest Questions and Answer :
Explanation: The first println prints variable a with value 1 and then increases the variable to 2.





Question : You have been given following code

public class Test {
public static void main(String[] args) {
int arr[] = new int[4];
arr[0] = 1;
arr[1] = 2;
arr[2] = 4;
arr[3] = 5;
int sum = 0;
try {
for (int pos = 0; pos <= 4; pos++) {
sum = sum + arr[pos];
}
} catch (Exception e) {
System.out.println("Invalid index");
}
System.out.println(sum);
}
}

What would be printed ?
 : You have been given following code
1. 12
2. Invalid Index 12
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails




Correct Answer : Get Lastest Questions and Answer :
Explanation: The loop
for (int pos = 0; pos <= 4; pos++) {
it should be pos <= 3, causes an exception,
which is caught.
Then the correct sum is printed.


Related Questions


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




Question : You have been given following code

class StaticField {
static int i = 7;

public static void main(String[] args) {
StaticField obj = new StaticField();
obj.i++;
StaticField.i++;
obj.i++;
System.out.println(StaticField.i + " " + obj.i);
}
}

what would be printed ?


 : You have been given following code
1. 10 10
2. 8 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 7 10




Question : Which declaration initializes a boolean variable?

 : Which declaration initializes a boolean variable?
1. boolean h = 1;
2. boolean k = 0;
3. Access Mostly Uused Products by 50000+ Subscribers
4. boolean j = (1 < 5);




Question : Which two are Java Exception classes?
A. SercurityException
B. DuplicatePathException
C. IllegalArgumentException
D. TooManyArgumentsException

 : Which two are Java Exception classes?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. A,C