Premium

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



Question : The catch clause argument is always of type .

A. Exception
B. Exception but NOT including RuntimeException
C. Throwable
D. RuntimeException
E. CheckedException


 : The catch clause argument is always of type .
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. D
5. E




Correct Answer : Get Lastest Questions and Answer :
Explanation: Because all exceptions in Java are the sub-class of java.lang.Exception class, you can have a single catch block that catches an exception of type Exception only.
Hence the compiler is fooled into thinking that this block can handle any exception. See the following example:
try
{
// ...
}
catch(Exception ex)
{
// Exception handling code for ANY exception
}
You can also use the java.lang.Throwable class here, since Throwable is the parent class for the application-specific Exception classes. However, this is discouraged in Java
programming circles. This is because Throwable happens to also be the parent class for the non-application specific Error classes which are not meant to be handled explicitly as they
are catered for by the JVM itself. Note: The Throwable class is the superclass of all errors and exceptions in the Java language.
Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.
A throwable contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.





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



Correct Answer : Get Lastest Questions and Answer :






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



Correct Answer : Get Lastest Questions and Answer :
Explanation:

Explanation:


Related Questions


Question : Which three statements are benefits of encapsulation?
A. Allows a class implementation to change without changing t he clients
B. Protects confidential data from leaking out of the objects
C. Prevents code from causing exceptions
D. Enables the class implementation to protect its invariants
E. Permits classes to be combined into the same package
F. Enables multiple instances of the same class to be created safely
 : Which three statements are benefits of encapsulation?
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E,F

5. A,B,D



Question : Which statement will empty the contents of a StringBuilder variable named sb?

 : Which statement will empty the contents of a StringBuilder variable named sb?
1. sb.deleteAll();
2. sb.delete(0, sb.size());
3. Access Mostly Uused Products by 50000+ Subscribers
4. sb.removeAll();




Question : Given the code fragment:
System.out.println(2 + 4 * 9 - 3); //Line 21
System.out.println((2 + 4) * 9 - 3); // Line 22
System.out.println(2 + (4 * 9) - 3); // Line 23
System.out.println(2 + 4 * (9 - 3)); // Line 24
System.out.println((2 + 4 * 9) - 3); // Line 25
Which line of codes prints the highest number?
 : Given the code fragment:
1. Line 21
2. Line 22
3. Access Mostly Uused Products by 50000+ Subscribers
4. Line 24

4. Line 25





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





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






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