Premium

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



Question : Given the code fragment:

Which modification enables the code fragment to print TrueDone?

  : Given the code fragment:
1. Replace line 5 With String result = "true";
Replace line 7 with case "true":
2. Replace line 5 with int opt = l;
Replace line 7 with case 1 :

3. At line 9, remove the break statement.
4. Remove the default section.



Correct Answer : 2





Question : Given the code fragment:
Which modification enables the code to print 54321?
 : Given the code fragment:
1. Replace line 6 with System, out. print (x--) ;
2. At line 1, insert x --;
3. Replace line 6 with --x; and, at line 7, insert system, out. print (x);
4. Replace line 12 With return (x > 0) ? false: true;




Correct Answers: 1
Explanation:






Question : Given the code fragment:
What is the result?
  :  Given the code fragment:
1. Reading Card
Card
2. Compilation fails only at line n1.
3. Compilation fails only at line n2.
4. Compilation fails only at line n3.
5. Compilation fails at both line n2 and line n3.


Correct Answer : 4

Explanation: There is no need to catch RuntimeException . However, Exception or any subclass of Exception you have to catch (These are checked exception)



Related Questions


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. Runnable run = 0 > System.out.println("Run");
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. Fresco : Fresco
4. A NullPointerException is thrown at runtime





Question : You have been given below code

boolean log3 = (5.0 != 6.0) && (4 != 5);
boolean log4 = (4 != 4) || (4 == 4);
System.out.println("\n log3:" + log3 + "\n log4 : " + log4);

When you execute this code, what would be printed ?
   : 	You have been given below code
1. log3:false
log4:true
2. log3:true
log4:true
3. log3:true
log4:false
4. log3:false
log4:false






Question : You have been given following code

public class Test {
static boolean bVar;

public static void main(String[] args) {
boolean bVar1 = true;
int count = 8;
do {
System.out.println("Hello Java! " + count);
if (count >= 7) {
bVar1 = false;
}
} while (bVar != bVar1 && count > 4);
count -= 2;
}
}

When you run it, what would be printed ?

  : You have been given following code
1. Hello Java! 8 Hello Java! 6 Hello Java! 4
2. Hello Java! 8 Hello Java! 6
3. Hello Java! 8
4. Compilation fails




Question : You have been given following code

public class TestLoop {
public static void main(String[] args) {
int array[] = { 0, 1, 2, 3, 4 };
int key = 3;
for (int pos = 0; pos < array.length; ++pos) {
if (array[pos] == key) {
break;
}
}
System.out.print("Found " + key + "at " + pos);
}
}

What is the result?

  : You have been given following code
1. Found 3 at 2
2. Found 3 at 3
3. Compilation fails
4. An exception is thrown at runtime




Question : A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently,
will allow the program to compile?

A. Catch the exception in the method doSomething().
B. Declare the exception to be thrown in the doSomething() method signature.
C. Cast the exception to a RunTimeException in the doSomething() method.
D. Catch the exception in the method that calls doSomething().
 : A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently,
1. A,B
2. B,C
3. C,D
4. A,D

5. A,C