Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : What would be the output when you run below code ?

package com.hadoopexam;

class Welcome {
public void print(Integer i) {
System.out.println("Integer value");
}

public void print(int i) {
System.out.println("primitive int value ");
}

public void print(long i) {
System.out.println("primitive long value");
}

public static void main(String args[]) {
Welcome wel = new Welcome();
wel.print(10);
}
}
 : What would be the output when you run below code ?
1. It will print "Integer value".

2. It will print "primitive int value "

3. It will print "primitive long value"

4. It will give Runtime Error. Method Ambiguity found.


Correct Answer : 3
Explanation: The code will match with int literal value and not with the Integer Class or long primitives.




Question : You have been given below code, what is the expected behavior when executed with -ea option

package com.hadoopexam;

public class Welcome {
public static void main(String[] args) {
int val1 = 10;
int val2 = -1;
assert (val2 >= 1) : "Invalid value have been provided";
int result = val1 / val2;
System.out.println(result);
}
}

 : You have been given below code, what is the expected behavior when executed with -ea option
1. It will run and produce output as -10

2. It will run and produce output as 0

3. It will run and produce output as -1

4. It will run and throw AssertionError: Invalid value have been provided


Correct Answer : 4
Explanation: As we know Assertion assumption is correct, then nothing will happen. But if assertion assumption is not correct it will throw assertion error.




Question : You have been given below two class in separate files. What is the correct replacement for the XXXXX?

package com.hadoopexam;

public class Welcome {
protected void print() {
System.out.println("Parent Class");
}
}

package com.hadoopexam;

public class Company extends Welcome {
XXXXX void display() {
System.out.println("Child Class");
}
}

 : You have been given below two class in separate files. What is the correct replacement for the XXXXX?
1. You can use only abstract,

2. You can use public or protected

3. You can only use public

4. You can only use protected.


Correct Answer : 2
Explanation: : You can use either public or protected. As access modifier you cannot restrict. You can have only more wider or same access modifiers in child class.
If method is overridden.


Related Questions


Question : You have been given below code, what will be printed once executed?

package com.hadoopexam;

import java.util.Map;
import java.util.TreeMap;

class Welcome {

public static void main(String[] args) {
Map user = new TreeMap<>();
user.put (1007, "Akash");
user.put (1002, "Kamlesh");
user.put (1001, "Bilash");
user.put (1003, "Bimal");
System.out.println (user);
}
}
 : You have been given below code, what will be printed once executed?
1. {1001=Bimal, 1002=Kamlesh, 1003=Bimal, 1007=Akash}

2. {1007=Akash, 1001=Bimal, 1003=Bimal, 1002=Kamlesh }

3. {1001=Bimal, 1002=Kamlesh, 1007=Akash}

4. {1007=Akash, 1001=Bimal, 1002=Kamlesh }

5. TreeMap is always sorted by Keys. Map can not have duplicate keys, but it can have duplicate values.


java.util.TreeMap.TreeMap()

Constructs a new, empty tree map, using the natural ordering of its keys. All keys inserted into the map must implement the Comparable interface. Furthermore, all such keys
must be mutually comparable: k1.compareTo(k2) must not throw a ClassCastException for any keys k1 and k2 in the map. If the user attempts to put a key into the map that
violates this constraint (for example, the user attempts to put a string key into a map whose keys are integers), the put(Object key, Object value) call
will throw a ClassCastException.



Question : You have been given below code, what behavior are you expecting?

package com.hadoopexam;

interface ParentInterface {
default void call() {
System.out.println("Why are you not working?");
}
}

@FunctionalInterface
interface ChildInterface extends ParentInterface {
@Override
abstract void call();
}

class Welcome {
public static void main(String[] args) {
ChildInterface cInterface = () -> System.out.println("Welcome to HadoopExam Learning Resources");
cInterface.call();
}
}
 : You have been given below code, what behavior are you expecting?
1. There will be a compile time error, as child interface can not override parent interface abstract method.

2. It will given compile time error, because ChildInterface is not a correctr functional interface.

3. This program compile and run perfectly and prints Why are you not working?.

4. This program compile and run perfectly and prints Welcome to HadoopExam Learning Resources.




Question : You have been given below code, what is the behavior you are expecting?

package com.hadoopexam;


class Welcome {

int id;
String name;

public Welcome(int id, String name) {
this.id = id;
this.name = name;
}

public boolean equals(Object obj) { // line n1
boolean output = false;
Welcome b = (Welcome) obj;
if (this.name.equals(b.name))
output = true;
return output;
}

public static void main(String[] args) {
Welcome wel1 = new Welcome(9199, "Hadoop User");
Welcome wel2 = new Welcome(2099, "Hadoop User");
System.out.println(wel1.equals(wel2)); // line n2
}

}


 : You have been given below code, what is the behavior you are expecting?
1. It will compile time error, as you have not overridden the hashCode() method.

2. It will give compile time error, you have to replace System.out.println(wel1.equals((Object)wel2));

3. It will compile and run, and print true

4. It will compile and run and print false.


Question : You have been given below code, what is the behavior you can expect by looking at the code?

public class Welcome {
public Welcome() {
System.out.println("In Welcome constructor ");
}

public void hello() {
enum Company { HADOOPEXAM, QUICKTECHIE, TRAINING4EXAM }
}
}


 : You have been given below code, what is the behavior you can expect by looking at the code?
1. This code will compile perfectly.

2. This code will compile cleanly without any compiler warnings or errors, and when used, will generate a runtime exception

3. This code will compile cleanly without any compiler warnings or errors, and when used, will run without any problems

4. This code will generate compile time error.



Question : You have been given following Parent child Interface and classes.

package com.hadoopexam;

interface Parent {
default void call() {
System.out.println("Parent...");
}
}

package com.hadoopexam;

interface Child1 extends Parent {
default void call() {
System.out.println("Child1...");
}
}

package com.hadoopexam;

interface Child2 {
public static void call() {
System.out.println("Child 2..");
}
}

package com.hadoopexam;

public class GrandChild implements Child2, Child1 {
public static void main(String[] args) {
new GrandChild().call();
}
}

What happens, when you run above GrandChild application?


 : You have been given following Parent child Interface and classes.
1. There will be a compile time error. Because you try to implement multiple inheritance.

2. There will be a compile time error. Because there is a confusion which call() method should be called.

3. There will be a no compile time error, and it will print "Child1..." when executed.

4. There will be a no compile time error, and it will print "Child2..." when executed.




Question : You have been given following code, with the LambdaFunction.
package com.hadoopexam;

class Welcome {
@FunctionalInterface
interface HadoopFunction {
int call(int j);

boolean equals(java.lang.Object arg0);
}

public static void main(String[] args) {
HadoopFunction hadoopFunction = val -> val * new Integer(6); // n1
System.out.println(hadoopFunction.call(2));
}
}

 : You have been given following code, with the LambdaFunction.
1. There will be a compile time error. Because there is no lambda function defined which can take Integer as an argument.

2. There will be a compile time error. Because there is no lambda function defined which can take two Integer values as argument2.

3. There will be a compile time error. Because there is no lambda function defined for equals method.

4. The program will run and compile perfectly, because auto unboxing will be applied and it will print 12.