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 : :
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





Question :

package p1;
public interface DoInterface {
void method1(int n1); // line n1
}

package p3;
import p1.DoInterface;
public class DoClass implements DoInterface {
public DoClass(int p1) { }
public void method1(int p1) { } // line n2
private void method2(int p1) { } // line n3
}

public class Test {
public static void main(String[] args) {
DoInterface doi= new DoClass(100); // line n4
doi.method1(100);
doi.method2(100);
}
}
Which change will enable the code to compile?

 :
1. Adding the public modifier to the declaration of method1 at line n1
2. Removing the public modifier from the definition of method1 at line n2
3. Access Mostly Uused Products by 50000+ Subscribers
4. Changing the line n4 DoClass doi = new DoClass ( );




Question : Consider

Integer number = Integer.valueOff 808.1");

Which is true about the above statement?

 : Consider
1. The value of the variable number will be 808.1
2. The value of the variable number will be 808
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NumberFormatException will be throw.
5. It will not compile




Question : You have been given following code

public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = " + ii);
ii = ii + 1;
}
}
}

What is the result?

 : You have been given following code
1. ii = 0 ii = 2
2. ii = 0 ii = 1ii = 2 ii = 3
3. Access Mostly Uused Products by 50000+ Subscribers

4. Compilation fails.




Question : Given the code fragment:
System.out.printIn("Result: " + 2 + 3 + 5);
System.out.printIn("Result: " + 2 + 3 * 5);
What is the result?

 : Given the code fragment:
1. Result: 10 Result: 30
2. Result: 10 Result: 25
3. Access Mostly Uused Products by 50000+ Subscribers
4. Result: 215 Result: 215

5. Compilation fails




Question : You have been given following code

public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;

public void display() {
System.out.println("Name: " + name + " Major: " + major);
}

public boolean isFullTime() {
return fulltime;
}
}


public class TestStudent {
public static void main(String[] args) {
Student bob = new Student();
bob.name = "Bob";
bob.age = 18;
bob.year = 1982;
}
}

What is the result?

 : You have been given following code
1. year is set to 1982.
2. bob.year is set to 1982
3. Access Mostly Uused Products by 50000+ Subscribers
4. A compile time error is generated.