Premium

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



Question : You have been given two separate classes as below.

public class MyException extends RuntimeException { }

public class Test {
public static void main(String[] args) {
try {
method1();
} catch (MyException ne) {
System.out.print("A");
}
}

public static void method1() { // line n1
try {
throw Math.random() > 0.5 ? new MyException()
: new RuntimeException();
} catch (RuntimeException re) {
System.out.print("B");
}
}
}

What is the result?

 : You have been given two separate classes as below.
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. AB
5. A compile time error occurs at line n1




Correct Answer : Get Lastest Questions and Answer :





Question : You have been given Java Application as below code

public class App {
String myStr = "7007";

public void doStuff(String str) {
int myNum = 0;
try {
String myStr = str;
myNum = Integer.parseInt(myStr);
} catch (NumberFormatException ne) {
System.err.println("Error");
}
System.out.println("myStr: " + myStr + ", myNum: " + myNum);
}

public static void main(String[] args) {
App obj = new App();
obj.doStuff("9009");
}
}

What happen/print, when you execute this code ?

  : You have been given Java Application as below code
1. myStr: 9009, myNum: 9009
2. myStr: 7007, myNum: 7007
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails




Correct Answer : Get Lastest Questions and Answer :
Explanation:




Question : Which two are benefits of polymorphism?
A. Faster code at runtime
B. More efficient code at runtime
C. More dynamic code at runtime
D. More flexible and reusable code
E. Code that is protected from extension by other classes

 : Which two are benefits of polymorphism?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D
5. A,E



Correct Answer : Get Lastest Questions and Answer :



Related Questions


Question : You have been given following code

class StaticField {
static int i = 7;

public static void main(String[] args) {
StaticField obj = new StaticField();
obj.i++;
StaticField.i++;
obj.i++;
System.out.println(StaticField.i + " " + obj.i);
}
}

what would be printed ?


 : You have been given following code
1. 10 10
2. 8 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 7 10




Question : Which declaration initializes a boolean variable?

 : Which declaration initializes a boolean variable?
1. boolean h = 1;
2. boolean k = 0;
3. Access Mostly Uused Products by 50000+ Subscribers
4. boolean j = (1 < 5);




Question : Which two are Java Exception classes?
A. SercurityException
B. DuplicatePathException
C. IllegalArgumentException
D. TooManyArgumentsException

 : Which two are Java Exception classes?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. A,C




Question : What is the proper way to defined a method that take two int values and returns their sum as an int value?

 : What is the proper way to defined a method that take two int values and returns their sum as an int value?
1. int sum(int first, int second) { first + second; }
2. int sum(int first, second) { return first + second; }
3. Access Mostly Uused Products by 50000+ Subscribers
4. int sum(int first, int second) { return first + second; }

5. void sum (int first, int second) { return first + second; }




Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}

What is the result?
 : You have been given following code
1. 8
2. 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 10
5. Compilation fails




Question : You have been given following code

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}
}

class AnotherSampleClass extends SampleClass {
}

When you execute it, what will be printed ?


 : You have been given following code
1. sc: class Object asc: class AnotherSampleClass
2. sc: class SampleClass asc: class AnotherSampleClass
3. Access Mostly Uused Products by 50000+ Subscribers
4. sc: class AnotherSampleClass asc: class AnotherSampleClass