Sudipta Das

Greenhorn
+ Follow
since Apr 05, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sudipta Das

Originally posted by Sudipta Das:
All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character)

1.are public
2.are serializable
3.are immutatable
4.extend java.lang.Number
5.are final



I suppose my question was misinterpreted. I meant to ask which is the correct answer of the fol. question :
All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character)

1.are public
2.are serializable
3.are immutatable
4.extend java.lang.Number
5.are final
if(" String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");

Answers
1.the code will compile an print "Equal".
2.the code will compile an print "Not Equal".
3.the code will cause a compiler error

Is 1 the correct answer ?
Which is the correct answer ?
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
1.The code does not compile.
2.The code compiles cleanly and shows "Object Version".
3.The code compiles cleanly and shows "String Version"
4.The code throws an Exception at Runtime.
Which is the correct answer for this quiz ?

public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(java.io.IOException t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
1.Compiler error complaining about the catch block where no IOException object can ever be thrown.
2.Compiler error - IOException not found. It must be imported in the first line of the code.
3.No compiler error. The lines "Before Try" and "At the end" are printed on the screen.
Which of the following statements are true?

1.A method can throw an Exception
2.A method can return an Exception
All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character)

1.are public
2.are serializable
3.are immutatable
4.extend java.lang.Number
5.are final

public class AQuestion
{
private int i = giveMeJ();
private int j = 10;
private int giveMeJ()
{
return j;
}
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Which is the correct answer :
1.Compiler error complaining about access restriction of private variables of AQuestion.
2.Compiler error complaining about forward referencing.
3.No Compilation error - The output is 0;
4.No Compilation error - The output is 10;
Select all of the following methods that are instance methods of the Thread class, excluding any methods deprecated in Java 1.2.
Ans :
a. start()
b. stop()
c. run()
d. sleep(long msec)
What will appear in the standard output when you run the Tester class?
1. class Tester {
2. int var;
3. Tester(double var) {
4. this.var = (int)var;
5. }
6. Tester(int var) {
7. this("hello");
8. }
9. Tester(String s) {
10. this();
11. System.out.println(s);
12. }
13. Tester() {
14. System.out.println("good-bye");
15. }
16. public static void main(String args[]) {
17. Tester t = new Tester(5);
18. }

Ans :
a. "hello"
b. 5
c. "hello" followed by "good-bye"
d. "good-bye" followed by "hello"
What letters are written to the standard output with the following code?
1. class Unchecked {
2. public static void main(String args[]) {
3. try {
4. method();
5. } catch(Exception e) { }
6. }
7. static void method() {
8. try {
9. wrench();
10. System.out.println("a");
11. } catch(ArithmeticException e) {
12. System.out.println("b");
13. } finally {
14. System.out.println("c");
15. }
16. System.out.println("d");
17. }
18. static void wrench() {
19. throw new NullPointerException();
20. }
21. }
22. Select all valid answers.

The answer provided is 'c'. Is that correct ?

Ans :
a. "a"
b. "b"
c. "c"
d. "d"
try {
2. tryThis();
3. return;
4. } catch(IOException x1) {
5. System.out.println("exception 1");
6. return;
7. } catch(Exception x2) {
8. System.out.println("exception 2");
9. return;
10. } finally {
11. System.out.println("finally");
12. }
what will appear in the standard output if tryThis() throws a IOException? (I am not sure of the answer)
Ans :
a. "exception 1" followed by "finally"
b. "exception 2" followed by "finally"
c. "exception 1"
d. "exception 2"
This question is also from the mock exam http://jquest.webjump.com. The correct answers are given as 'a' & 'b'. Is only 'b' not enough ? Please advise me.
What can you write at the comment //A in the following code so that this program writes the word "running" to the standard output?
1. class RunTest implements Runnable {
2. public static void main(String args[]) {
3. RunTest rt = new RunTest();
4. Thread t = new Thread(rt);
5. //A
6. }
7. public void run() {
8. System.out.println("running");
9. }
10. void go() {
11. start(1);
12. }
13. void start(int i) {
14. }
15. }
Select all valid answers.

Ans :
a. System.out.println("running");
b. t.start();
c. rt.start();
d. rt.start(1);
This question is from the mock exam http://jquest.webjump.com. The correct answers given are 'b' & 'c'. But I think only 'c' is correct. Please advise me.
Given the following code fragment.
1. switch( x ) {
2. case 100
3. System.out.println("One hundred"); break;
4. case 200
5. System.out.println("Two hundred"); break;
6. case 300
7. System.out.println("Three hundred"); break;
8. }
This question is from the mock exam http://jquest.webjump.com. The correct answer is given as 'a'. But I think both 'a' & 'c' are correct. Please advise me.

Choose all of the declarations of x that will not cause a compiler error.
Ans :
a. byte x=100;
b. short x=200;
c. int x = 300;
d. long x = 400;
This question is from the mock exam http://jquest.webjump.com. The correct answer is given as 'a'. But I think both 'a' & 'c' are correct. Please advise me.

You are creating a ToolBase class which will be extended by other programmers. The ToolBase class contains a single abstract method, createTool.
Which of the following statements are true?
Ans :
a. The ToolBase class must be declared abstract
b. The ToolBase class must not be declared final
c. The following variable declaration is illegal in any context "ToolBase myTB;"
What is the output of the following piece of code
1. int x = 6;
2. double d = 7.7;
3. System.out.println((x>d) ? 99.9 ; 9);

Ans :
a. 9
b. 9.0
c. 99.9