public class Welcome { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = null; try (BufferedReader _bufferedReader = new BufferedReader(new FileReader("resources\\Message.txt"))) { // line n1 _bufferedReader.lines().forEach(eachChar -> System.out.println(eachChar)); bufferedReader = _bufferedReader;// line n2 } bufferedReader.ready(); // line n3; } } 1. A compilation error occurs at line n3.
boolean java.io.BufferedReader.ready() throws IOException Tells whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready. Overrides: ready() in Reader Returns: True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. Throws: IOException - If an I/O error occurs
Question : You have been given below code, what is the behavior expected?
package com.hadoopexam;
public class Welcome { private String startCourse(String bname) { return "Watch " + bname; } }
class Child extends Welcome { public String startCourse(String url) { return "Complete " + url; } }
class Util { public static void main(String[] args) { Welcome p1 = new Welcome(); p1.startCourse("Hadoop Training"); //n1 Welcome child = new Child(); child.startCourse("http://hadoopexam.com/java"); //n2 } } 1. Watch Hadoop Training Complete http://hadoopexam.com/java
2. Watch Hadoop Training Watch http://hadoopexam.com/java
Correct Answer : Get Lastest Questions and Answer : Explanation: private method is not accessible in other classes. It will be accessible only in same class.
Question : Which of the following code snippet is correct? 1. class Welcome implements Callable { public int call() { System.out.println("In Callable.call()"); return 0; } }
2. class Welcome extends Callable { public Integer call() { System.out.println("In Callable.call()"); return 0; } }
Correct Answer : Get Lastest Questions and Answer : Explanation: Callable is interface, hence B cannot be correct. Call() methods can retrun Object not primitive type. Hence, option A is wrong.
V java.util.concurrent.Callable.call() throws Exception
Computes a result, or throws an exception if unable to do so. Returns: computed result Throws: Exception - if unable to compute a result