- 1
- 2
- 3
- …
- 20
- Next Page »
A Learning Portal from Recruitment India
Which of these classes can return more than one character to be returned to the input stream?
BufferedReader
Bufferedwriter
PushbachReader
CharArrayReader
Answer with explanation
Answer: Option CExplanation
PushbackReader class allows one or more characters to be returned to the input stream. This allows looking ahead in the input stream and performing action accordingly.
Workspace
What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}
Prints 7
Prints 10
Prints 0
Compilation fails
Answer with explanation
Answer: Option DExplanation
The code does not compile because the constructor of class A is declared as private. This creates a problem when the subclass constructor makes an implicit super() call to the parent class constructor at the time B is instantiated.
Since the code does not compile, all the other choices are incorrect. If the constructor of A had not been private, the output would have been 7.
Workspace
Which of the following declares an abstract method in an abstract Java class?
public abstract method();
public abstract void method();
public void abstract Method();
public void method() {}
Answer with explanation
Answer: Option BExplanation
public abstract void method();
Workspace