abstract class Welcome { Welcome() { System.out.println("Welcome Constructor"); }
protected void message() { System.out.println("Hello and welcome to HadoopExam.com"); } }
package com.hadoopexam;
class Child1 extends Welcome { int weight;
Child1(int weight) { //n1 this.weight = weight; }
public void message() { System.out.println("Welcome to Child 1 Class"); } }
class GrandChild1 extends Child1 { int age, height;
GrandChild1(int x, int y) { //n2 age = x; height = y; }
public void message() { System.out.println("Welcome to grand child class"); } }
Which of the following statement are correct, so that code will compile without error?
1. Replace n1 with this()
2. Replace n1 with super(x)
3. Replace n2 with super(x)
4. Replace n2 with super(x,y)
Correct Answer : 3 Explanation: As you know, when we have parent child relation. We should take care of constructor chaining as well. Suppose you are defining a constructor with argument in parent class e.g. Child1 class having one argument constructor. Hence, GrandChild1 constructor class have to explicitly call super constructor to get it compiled. And super(x) call should be the first line of constructor.
Question : Which of the following method(s) from Object class can be overridden? (Select all that apply.) A. finalize() B. clone() C. getClass() D. notify() E. wait()
1. A,B 2. B,C 3. C,D 4. D,E 5. A,E
Correct Answer : 1 Explanation: The methods finalize() and clone() can be overridden. The methods getClass(), notify(), and wait() are final methods and so cannot be overridden.
Question : You have been given below code, what is the expected behavior?
class Welcome extends RecursiveAction { // line n1 static final int MAX_INDEX_COUNT = 3; int startIndex, lastIndex; int[] data;
public Welcome(int[] data, int start, int end) { this.data = data; this.startIndex = start; this.lastIndex = end; }
protected void compute() { int sum = 0; if (lastIndex - startIndex <= MAX_INDEX_COUNT) { for (int i = startIndex; i < lastIndex; i++) { sum += data[i]; } System.out.println(sum); } else { new Welcome(data, startIndex + MAX_INDEX_COUNT, lastIndex).fork(); new Welcome(data, startIndex, Math.min(lastIndex, startIndex + MAX_INDEX_COUNT)).compute(); } }
public static void main(String[] args) { ForkJoinPool fjPool = new ForkJoinPool(); int data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; fjPool.invoke(new Welcome(data, 0, data.length)); } } 1. Code will give compile time error
2. Code will run and print 55
3. Code will run and print any one value between 0 to 55
4. Code will run and print 4 values, whose total will be 55
Correct Answer : 4 Explanation: It is a complete example of Fork-Join application. In this we have 1 to 10 values , total 10 elements. We are forking new compute task for each 3 indexes. Here we have 10 elements as below.
0 to 2 -> total will be (1+2+3) -> 6 3 to 5 -> total will be (4+5+6) -> 15 6 to 9 -> total will be (7+8+9) ->24 10 -> total will be 10
2. It will give "NullPointerException" when executed.
3. It will run perfectly and print as below. Welcome to HadoopExam Learning Resources Welcome to Training4Exam.com Welcome to QuickTechie Professional Network null
4. It will run perfectly and print as below. Welcome to HadoopExam Learning Resources Welcome to Training4Exam.com Welcome to QuickTechie Professional Network