Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice 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




Correct Answer : Get Lastest Questions and Answer :
Explanation: The for statement have this forms: for (init-stmt; condition; next-stmt) { body}
There are three clauses in the for statement.
The init-stmt statement is done before the loop is started, usually to initialize an iteration variable.
The condition expression is tested before each time the loop is done. The loop isn't executed
if the boolean expression is false (the same as the while loop).
The next-stmt statement is done after the body is executed. It typically increments an
iteration variable.




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





Correct Answer : Get Lastest Questions and Answer :
Explanation:





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



Correct Answer : Get Lastest Questions and Answer :
null Unix Linux Solarios
The first element, arr[0], has not been defined.



Related Questions


Question : You have been given following code

public class MainMethod {
void main() {
System.out.println("one");
}

static void main(String args) {
System.out.println("two");
}

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

void mina(object[] args) {
System.out.println("four");
}
}

What is printed out when the program is excuted?

 : You have been given following code
1. one
2. two
3. Access Mostly Uused Products by 50000+ Subscribers
4. four




Question : You have been given following code

int var1 = -5;
int var2 = var1--;
int var3 = 0;
if (var2 <lt; 0) {
var3 = var2++;
} else {
var3 = --var2;
}
System.out.println(var3);

What is the result?


 : You have been given following code
1. -6
2. -4
3. Access Mostly Uused Products by 50000+ Subscribers
4. 5

5. 4




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





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





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





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