Premium

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



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.



Correct Answer : Get Lastest Questions and Answer :
Explanation:






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



Correct Answer : Get Lastest Questions and Answer :
Explanation:

First line:
System.out.println("Result: " + 2 + 3 + 5); String concatenation is produced.

Second line:
System.out.println("Result: " + 2 + 3 * 5);
3*5 is calculated to 15 and is appended to string 2. Result 215.
The output is: Result: 235
Result: 215

Note #1:
To produce an arithmetic result, the following code would have to be used:
System.out.println("Result: " + (2 + 3 + 5));
System.out.println("Result: " + (2 + 1 * 5));
run:
Result: 10
Result: 7

Note #2:
If the code was as follows:
System.out.println("Result: " + 2 + 3 + 5");
System.out.println("Result: " + 2 + 1 * 5");
The compilation would fail.
There is an unclosed string literal, 5", on each line.






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.



Correct Answer : Get Lastest Questions and Answer :
Explanation:



Related Questions


Question : You have given code as shown and commands to compile and run are below.

javac HadoopExamApp.java
java HadoopExam 1 2 3

What would be printed.


 : You have given code as shown and commands to compile and run are below.
1. int HadoopExam 1
2. Object HadoopExam 1
3. Access Mostly Uused Products by 50000+ Subscribers
4. It failed in Compilation step/Command
5. It will compile successfully, but at runtime, it will through RuntimeException





Question : You have been given below code. What value it is going to print (Assume it is in a class)
  : You have been given below code. What value it is going to print (Assume it is in a class)
1. HadoopExam 0
HadoopExam 1
2. Null HadoopExam 0
Null HadoopExam 1
3. Access Mostly Uused Products by 50000+ Subscribers
Null
4. A NullPointerException is thrown at runtime.



Question : : You have been given below code fragement

StringBuilder sb = new StringBuilder ( ) ;
sb.append ("world");

Which code fragment prints Hello World?

  : :  You have been given below code fragement
1. sb.insert(0,"Hello "); System.out.println(sb);
2. sb.append(0,"Hello "); System.out.println(sb);
1. sb.add(0,"Hello "); System.out.println(sb);
2. sb.set(0,"Hello "); System.out.println(sb);





Question : Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?

  : Given the code fragment:
1. if (h1 = = h2)
2. if (h1.equals(h2))
3. Access Mostly Uused Products by 50000+ Subscribers
4. if (h1.same(h2))



Question : You have been given belwo interface declaration

interface Runnable {
public voide run();
}

Which of the following will create instance of Runnable type?

   : You have been given belwo interface declaration
1. Runnable run = 0 -> {
System.out.println("Run");
}
2. Runnable run = 0 -> System.out.println("Run");
3. Access Mostly Uused Products by 50000+ Subscribers
4. Runnable run => System.out.println("Run");
5. None of above





Question : You have been given below Java Code

public class Painting {
private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public static void main(String[] args) {
Painting obj1 = new Painting();
Painting obj2 = new Painting();
obj1.setType(null);
obj2.setType("Fresco");
System.out.print(obj1.getType() + " : " + obj2.getType());
}
}

When you run it, what would be printed ?


   : 	You have been given below Java Code
1. : Fresco
2. null : Fresco
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NullPointerException is thrown at runtime