Premium

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



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.


Correct Answer : 4
Explanation: This code will not compile because, enum can only be defined in a top-level class or interface and not within a method.




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.



Correct Answer : 3
Explanation: As we are extending two interfaces. Child1 and Child2. Both are having same method name call(). However, Child2 interface is having static call() method.
And child class cannot override the static methods of a parent interface. Hence, if you want to use call() method of Child2() class then , you should have called
as Child2.call() . But the Child1 is having an interface, which has defined a default call() method, which can be overridden.




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.


Correct Answer : 4
Explanation: It is valid to define an interface inside the class. As equals method is having the same signature as parent class of all the
classes Objects equals() method, hence it is not considered as abstract method of the functional interface. It is acceptable to leave the parameter type when there is only
one parameter and the parameter and return type are inferred from the LambdaFunction abstract method declaration int call(int j).
Since the lambda function is passed with the value 2, the returned value is 2 * new Integer(6), and hence 12 is printed in console.
There will be Auto Unboxing for Integer(6) to 6 as primitive values.


Related Questions


Question : You have been given below code, what is the expected behavior

package com.hadoopexam;

import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) {
Stream words = Pattern.compile(" ").splitAsStream("Hadoop Exam .com Quick Techie .com");
System.out.println(words.map(word -> word.length()).sum());
}
}
 : You have been given below code, what is the expected behavior
1. Code will give compile time error.

2. Code will give run time error.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run and compile perfectly and print 29




Question : You have been given below code, select the correct behavior
package com.hadoopexam;

import java.util.OptionalInt;
import java.util.stream.IntStream;

public class Welcome {
public static void main(String args[]) {
maxValue(IntStream.of(1,2,3,4,5)); // //n1
}

public static void maxValue(IntStream values) {
OptionalInt max = values.max(); //n2
if (max.ifPresent()) { //n3
System.out.print(max.getAsInt());
}
}
}
 : You have been given below code, select the correct behavior
1. Code will give compile time error.

2. Code will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print nothing



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.util.Optional;
import java.util.stream.Stream;

public class Welcome {
public static void main(String args[]) {
Stream.of("Hadoop ", "Exam ", ".com ", null).forEach(Welcome::changeCase);
}

private static void changeCase(String word) {
Optional str = Optional.ofNullable(word);
System.out.print(str.map(String::toUpperCase).orElse("NULL"));
}
}
 : You have been given below code, what is the expected behavior?
1. Code will give compile time error.

2. Code will give run time error.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print "Hadoop Exam .com NULL"



Question : You have been given following code snippet. Based on the below code, select the correct option which can have overridden method in child class.

package com.hadoopexam;

import java.nio.file.FileAlreadyExistsException;

class Parent {
private T test;

void call(T t) throws FileSystemException{
test = t;
System.out.println("Testing Method 1");
}
}
 : You have been given following code snippet. Based on the below code, select the correct option which can have overridden method in child class.
1. void call(T t) throws FileAlreadyExistsException{}

2. void call(T t) throws Exception{}

3. Access Mostly Uused Products by 50000+ Subscribers

4. None of the above



Question : You have been given following code. When you run it what is the expected output.

package com.hadoopexam;
class Welcome {
public static void call() {
try {
throw new ArrayIndexOutOfBoundsException();
} catch (ArrayIndexOutOfBoundsException boundException) {
RuntimeException runtimeException = new RuntimeException(boundException);
runtimeException.initCause(boundException);
throw runtimeException;
}
}

public static void main(String[] args) {
try {
call();
} catch (Exception exception) {
System.out.println(exception.getClass());
}
}
}
 : You have been given following code. When you run it what is the expected output.
1. class java.lang.RuntimeException

2. class java.lang.IllegalStateException

3. Access Mostly Uused Products by 50000+ Subscribers

4. class java.lang.ArrayIndexOutOfBoundsException



Question : You have been given below exception, select the correct behavior
package com.hadoopexam;

class Welcome {
public static void call() {
try {
throw new IndexOutOfBoundsException();
} catch (IndexOutOfBoundsException ioob) {
throw new Exception(ioob);
}
}

public static void main(String[] args) {
try {
call();
} catch (Exception e) {
System.out.println(e.getCause());
}
}
}
 : You have been given below exception, select the correct behavior
1. Code will give compile time error.

2. Code will run and print nothing.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run and print IllegalStateException