Premium

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



Question : Given: What is the result?




  : Given: What is the result?
1. C B A
2. C
3. A B C
4. Compilation fails at line n1 and line n2





Correct Answer : 3
Explanation: When you have hierarchy in java code, and calling a constructor will first call default constructor of super class. In given code, we are creating instance of
class C , which will call constructor of class C , before calling class C constructor it will call Class B constructor and Class B constructor will call default constructor of class
A (Hierarchy end here). Hence, first A, then B and then C will be printed here.







Question : Given the code fragment:

What is the result?

  : Given the code fragment:
1. [Robb, Rick, Bran]
2. [Robb, Rick]
3. [Robb, Bran, Rick, Bran]
4. An exception is thrown at runtime.


Correct Answer : 1
Explanation:
public boolean remove(object o)
Removes the first occurrence of the specified element from this list, if it is present (optional operation).
If this list does not contain the element, it is unchanged. More
formally, removes the element with the lowest index i such that (o==null ? get(i) == null : o.equals(get(i))) (if such an element exists).
Returns true if this list contained the
specified element (or equivalently, if this list changed as a result of the call).
Parameters:
o - element to be removed from this list, if present
Returns:
true if this list contained the specified element





Question :

1. Replace line n2 with
e.name="Joe";
e.contract=true;
e.salary=100;

2. Replace line n2 with
this.name="Joe";
this.contract=true;
this.salary=100;

3. Replace line n1 with
this.name=new String("Joe");
this.contract=new Boolean(true);
this.salary=new Double(100);

4. Replace line n1 with
name="Joe";
contract=TRUE;
salary=.0f;

5. Replace line n1 with
this("Joe", true, 100);

  :
1. 1,2
2. 1,3
3. 2,4
4. 4,5
5. 3,5






Correct Answer : 2
Explanation:





Related Questions


Question : Which two modifications,
made independently, enable the code to compile?

A. Make the method at line n1 public.
B. Make the method at line n2 public.
C. Make the method at line n3 public.
D. Make the method at line n3 protected.
E. Make the method at line n4 public.

 :  Which two modifications,
1. A,B

2. B,C

3. C,D

4. D,E


Question : What is the name of the Java concept that uses access modifiers to protect variables and hide
them within a class?

 :  What is the name of the Java concept that uses access modifiers to protect variables and hide
1. Encapsulation

2. Inheritance
3. Abstraction
4. Instantiation
5. Polymorphism



Question : Given the code fragment:

public static void main(String[] args){
short s1 = 200;
Integer s2 = 400;
Long s3 = (long) s1+s2; //line n1
String s4 = (String)(s3*s2); //line n2
System.out.println("Sum is " + s4);

}

What is the result?

 :  Given the code fragment:
1. Sum is 600
2. Compilation fails at line n1.
3. Compilation fails at line n2.
4. A ClassCastException is thrown at line n1.
5. A ClassCastException is thrown at line n2.





Question : Given the code fragment:

public static void main(String[] args){
String date = LocalDate.parse("2014-05-04").format(DateTimeFormatter.ISo_DATE_TIME);
System.out.println(date);
}

What is the result?


 :  Given the code fragment:
1. May 04, 2014T00:00:00.000
2. 2014-05-04T00:00: 00. 000
3. 5/4/14T00:00:00.000
4. An exception is thrown at runtime.




Question : Given the code fragment:

if(aVar++ <10){
System.out.println(aVar + " Hello World!");
}else{
System.out.println(aVar + " Hello Universe!");
}

What is the result if the integer aVar is 9?


  : Given the code fragment:
1. Hello World!
2. Hello Universe!
3. Hello World
4. Compilation fails.




Question : Given

What is the result?


  : Given
1. 200.0 : 100.0
2. 400.0 : 200.0
3. 400.0 : 100.0
4. Compilation fails.