hello everybody,
These are the few ques from various mock exams in which I've got doubts .I'll be thankful if anyone can help me with these ques
Q1.Which of the following would be a valid inner class for this class?
Select all valid answers.
a) class B {
}
b) class B extends A {
}
c) class B {
B() {
System.out.println("i = " + i);
}
}
d) class B {
class A {
}
}
e) class A {
}
ans given is a&c.But I think b is also correct.
Q2.
Which statement is true about a non-static inner class?
A.It must implement an interface.
B.It is accessible from any other class. //why is this option wrong?
C.It can only be instantiated in the enclosing//ans
class.
D.It must be final if it is declared in a method
scope.
E.It can access private instance variables in the
enclosing object. //ans
Q3.
for(int i=0; i<N; i++)>
String tmp = "test"; //why this loop shows compilation error as variable redeclaration
Q4.Why '\u000A' is invalid expr while '\uBABE' is valid?
Q5.
. Which of the following places no constraints on the type of elements, order of elements, or repetition of elements with in the collection.?
A) Collection
B) collection//ans given
C) Map
D) Set
Do we have anything as collection?
Q6.
import java.io.*;
public class TestIPApp {
public static void main(String args[]) {
RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
file.writeBoolean(true);
file.writeInt(123456);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.0001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
Select correct answer:
A) 123456
B) 7890 //ans
C) 1000000
D) .0001
Can anyone explain why is this option correct?
Thanks in advance,
Mamta