Premium

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



Question : You have been given below code

package WQ5;

abstract class A1 {
public abstract void m1();

public void m2() {
System.out.println("Green");
}
}

abstract class A2 extends A1 {
public abstract void m3();

public void m1() {
System.out.println("Cyan");
}

public void m2() {
System.out.println("Blue");
}
}

public class A3 extends A2 {
public void m1() {
System.out.println("Yellow");
}

public void m2() {
System.out.println("Pink");
}

public void m3() {
System.out.println("Red");
}

public static void main(String[] args) {
A2 tp = new A3();
tp.m1();
tp.m2();
tp.m3();
}
}

When you run it , what would be result ?


 : You have been given below code
1. Yellow Pink Red
2. Cyan Blue Red
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation Fails



Correct Answer : Get Lastest Questions and Answer :







Question : You are writing a method that is declared not to return a value. Which two are permitted in the method body?

A. omission of the return statement
B. return null;
C. return void;
D. return;



 : You are writing a method that is declared not to return a value. Which two are permitted in the method body?
1. A,B
2. A,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D




Correct Answer : Get Lastest Questions and Answer :

Explanation: Any method declared void doesn't return a value. It does not need to contain a return
statement, but it may do so. In such a case, a return statement can be used to branch out of a
control flow block and exit the method and is simply used like this:return;





Question : You have been given below code

import java.util.*;

public class Ref {
public static void main(String[] args) {
StringBuilder s1 = new StringBuilder("Hello Java!");
String s2 = s1.toString();
List lst = new ArrayList();
lst.add(s2);
System.out.println(s1.getClass());
System.out.println(s2.getClass());
System.out.println(lst.getClass());
}
}

When you run it, what would be result ?


 :  You have been given below code
1. class java.lang.String class java.lang.String class java.util.ArrayList
2. class java.lang.Object class java.lang. Object class java.util.Collection
3. Access Mostly Uused Products by 50000+ Subscribers
4. class java.lang.StringBuilder class java.lang.String class java.util.List





Correct Answer : Get Lastest Questions and Answer :




Related Questions


Question : Which three statements describe the object-oriented features of the Java language?

A. objects cannot be reused.
B. A subclass can inherit from a superclass.
C. objects can share behaviors with other objects.
D. A package must contain more than one class.
E. object is the root class of all other objects.
F. A main method must be declared in every class.

 :  Which three statements describe the object-oriented features of the Java language?
1. A,B,D
2. B,C,E
3. A,C,F
4. B,C,F




Question : Given:


And given the commands:
javac Test.Java
Java Test Hello
What is the result?
 :   Given:
1. Success
2. Failure
3. Compilation fails.
4. Anexception is thrown at runtime





Question : Given the code fragment

public static void main(String[] args) {
double discount = 0;
int qty = Integer.parseInt(args[0]);
//line n1
}

And given the requirements:
- If the value of the qty variable is greater than or equal to 90, discount = 0.5
- If the value of the qty variable is between 80 and 90, discount = 0.2
Which two code fragments can be independently placed at line n1 to meet the requirements?

  : Given the code fragment
1. A,C
2. B,C
3. C,D
4. D,E





Question : Given the code fragment. What is the result?
  : Given the code fragment. What is the result?
1. 10 : 10
2. 5 : 5
3. 5 : 10

4. Compilation fails




Question : Given the code fragment:

7. StringBuilder sb1 = new StringBuilder("Duke");
8. String str1 = sb1.toString();
9. //Insert code here
10. System.out.println(str1==str2);

Which code fragment, when inserted at line 9, enables the code to print true?

  : Given the code fragment:
1. String str2 = str1;
2. String str2 = newString (str1);
3. String str2 =sb1. toString ();
4. String str2 = "Duke";




Question : Given the code fragment: Assume that the system date is June , . What is the result?

LocalDate date1 = LocalDate.now();
LocalDate date2 = LocalDate.of(2014,6,20);
LocalDate date3 = LocalDate.parse("2014-06-20", DateTimeFormatter.ISo_DATE);
System.out.println("date1 = " + date1);
System.out.println("date2 = " + date2);
System.out.println("date3 = " + date3);

  : Given the code fragment: Assume that the system date is June , . What is the result?
1.
date1=2014-06-20
date2=2014-06-20
date3=2014-06-20
2.
date1=06/20/2014
date1=2014-06-20
date1=Jun 20, 2014
3. Compilation Fails
4. A DateParseException is thrown at runtime.