Premium

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



Question : Given:

System.out.println("5 + 2 = " + 3 + 4 );
System.out.println("5 + 2 = " + (3 + 4) );

What is the result?

  : Given:
1. 5 + 2 = 34
5 + 2 = 34
2. 5 + 2 + 3 + 4
5 + 2 = 7
3. 7 = 7
7 + 7
4. 5 + 2 = 34
5 + 2 =7




Correct Answer 4

Explanation: In first statment it will consider each element as a string because one element in string and no special format as in second statment. In second statement, it will give
priority to expression which is in () hence first it will calculate 3+4 which is 7 and then appended to string.

If either (or both) of the operands of the + operator is a string, the other is automatically cast to a string. String concatenation and addition have the same precedence. Since they
are left-associative, the operators are evaluated left-to-right. The parentheses in the second statement ensures that the second + operator performs addition instead of string concatenation.







Question : Given the code fragment:
System.out.printIn("Result: " + 2 + 3 + 5);
System.out.printIn("Result: " + 2 + 3 * 5);
What is the result?

 : Given the code fragment:
1. Result: 10 Result: 30
2. Result: 10 Result: 25
3. Result: 235 Result: 215
4. Result: 215 Result: 215

5. Compilation fails



Correct Answer : 3
Explanation:

First line:
System.out.println("Result: " + 2 + 3 + 5); String concatenation is produced.

Second line:
System.out.println("Result: " + 2 + 3 * 5);
3*5 is calculated to 15 and is appended to string 2. Result 215.
The output is: Result: 235
Result: 215

Note #1:
To produce an arithmetic result, the following code would have to be used:
System.out.println("Result: " + (2 + 3 + 5));
System.out.println("Result: " + (2 + 1 * 5));
run:
Result: 10
Result: 7

Note #2:
If the code was as follows:
System.out.println("Result: " + 2 + 3 + 5");
System.out.println("Result: " + 2 + 1 * 5");
The compilation would fail.
There is an unclosed string literal, 5", on each line.










Question : Given:

What is the result?



  : Given:
1. Base
DerivedA
2. Base
DerivedB
3. DerivedB
DerivedB
4. DerivedB
DerivedA
5. A classcast Except ion is thrown at runtime.


Correct Answer 3

Explanation: As both b1 and b4 point to same real instance of Class DerivedB . Hence, at runtime it will call method defined in DerivedB class.
Casting with super class, does not change actual underline instance.




Related Questions


Question : Given:

Which statement is true?
  : Given:
1. Both p and s are accessible by obj.
2. only s is accessible by obj.
3. Both r and s are accessible by obj.
4. p, r, and s are accessible by obj.


Question : You are developing a banking module.
You have developed a class
named ccMask that has a maskcc method.

Given the code fragment as shown in image:
  : You are developing a banking module.
1. A,B
2. B,C
3. C,D
4. A,D




Question : Given the following code:


public static void main(String args[]){

String[] planets = {"Mercury" , "Venus", "Earth" , "Mars"};

System.out.println(planets.length);
System.out.println(planets[1].length());
}

What is the output?



  : Given the following code:
1. 4

2. 3

3. 4

4. 4

5. 4




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