Premium

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



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.




Question : :
int [] array = {1,2,3,4,5};
for (int i: array) {
if ( i < 2) {
keyword1 ;
}
System.out.println(i); if ( i == 3) {
keyword2 ;
}}

What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?
 : :
1. continue, break
2. break, break
3. Access Mostly Uused Products by 50000+ Subscribers
4. continue, continue




Correct Answer : Get Lastest Questions and Answer :
Explanation:




Related Questions


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




Question : What is the proper way to defined a method that take two int values and returns their sum as an int value?

 : What is the proper way to defined a method that take two int values and returns their sum as an int value?
1. int sum(int first, int second) { first + second; }
2. int sum(int first, second) { return first + second; }
3. Access Mostly Uused Products by 50000+ Subscribers
4. int sum(int first, int second) { return first + second; }

5. void sum (int first, int second) { return first + second; }




Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}

What is the result?
 : You have been given following code
1. 8
2. 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 10
5. Compilation fails




Question : You have been given following code

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}
}

class AnotherSampleClass extends SampleClass {
}

When you execute it, what will be printed ?


 : You have been given following code
1. sc: class Object asc: class AnotherSampleClass
2. sc: class SampleClass asc: class AnotherSampleClass
3. Access Mostly Uused Products by 50000+ Subscribers
4. sc: class AnotherSampleClass asc: class AnotherSampleClass