• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Some Mock Exam Questions

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing mock test Valiveru's Home.
I have the fol doubts about some anwsers.

1 Given the code below
public class ThreadDemo extends Thread[
public void run(){
System.out.println("Thread started");
try{
Thread.sleep(20000); //20 seconds sleep
System.out.println("I am Back from my sleep");
}
catch(InterruptedException e){
System.out.println("I got Interrupted");
}
}
}
Which of the following statements are true?
A.Exactly 20 seconds after the start method
is called "I am Back from my sleep" be printed.
B.We can be sure that atleast after 20 seconds elapsed,
"I am Back from sleep" will be printed.
C.The delay between output "Thread started" and "I am Back
from sleep" is less or more than 20 seconds.
D.None of the above.
The answer is B. But I think should be D. because if thread is interrupted,then "I am Back from sleep" will never be printed.
2. Which of the following are true about inner classes

A.Inner classes can only be instantiated in its outer class
B.Inner classes can be protected or private
C.Anonymous inner class can be both an explicit subclass
and implements an interface.
D.Anonymous inner classes declare and instantiated at the
same place.
E.An inner class can be static only when it's outer class
is static.
F.An instance of an Anonymous inner class can only be
created in it's outer class
The answer is B and D.But I think should be B,D,and F.

3. Select all the following statements about 'wait' method that are true
A.wait() is static final method that cannot be overrided.
B.wait() is an instance method of object class.
C.wait() is an instance method of Thread class.
D.Thread must have lock an the object involved to call
wait().
The answer is B and D.
But I think B, C and D. Because Thread is a subclass of Object,so it inherits wait() method from Object.So wait() should be an instance method of Thread class too.
4. Given that method aMethod() throws BaseException, SubException and RuntimeException of the following exception hierarchy
java.lang.Exception
|
+ - - BaseException
|
+ - - SubException
|
+ - - java.lang.RuntimeException

Which of the following are legal
A.public class MyClass {
public void myMethod(){
aMethod();
}
}
B.public class MyClass{
public void myMethod() throws BaseException,RuntimeException{
aMethod();
}
}
C.public class MyClass{
public void myMethod() throws BaseException{
aMethod();
}
}
D.public class MyClass{
public void myMethod() throws Exception{
aMethod();
}
}
E.public class MyClass{
public void myMethod() throws RuntimeException {
aMethod();
}
}
Answer are C and D.Why B is wrong?Since a method can freely throw RuntimeException which is not a checked Exception.

5. Which of the follwing is true about static modifier.
A.static can be applied to : instance variables, methods,
code Segments and classes.
B.a static method cannot be overridden.
C.inner classes can be both static & private.
D.a static reference cannot be made through non static
method or code block.
E.abstract & static both can be applied together to a
method.
The answer are B,C,D.
Obviously,D is wrong. I choose B,C.
Hope anyone can clear these questions
Thx in advance
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bin,

1. D) - The other answers are ambiguous. If the answer C had been "We can be sure that atleast after 20 seconds elapsed,
"I am Back from sleep" will be printed unless interrupted" then i would have voted for it.

2. I am not sure. I have to learn more about Anonymous Inner classes.
3. B and D.. All the classes implicitly extend the Object class does that mean all the methods defined in Object are instance methods of the sub-class.?
4. B,C and D. For B... Even if it was checked Exception as it is in the lower part of the hierarchy.. I feel that there shouldn't be any problem in mentioning it explicitly... since BaseException has already been mentioned in the throws clause.
Thanks & Regards,
Nijeesh.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic