Sunday, December 18, 2016

JAVA Interview Question 10 - 20

JAVA Interview Question  10 - 20

Q. 11
11. class Alpha {
12. public void foo() { System.out.print(“Afoo”); }
13. }
14. public class Beta extends Alpha {
15. public void foo() { System.out.print(“Bfoo”); }
16. public static void main(String[] args) {
17. Alpha a = new Beta();
18. Beta b = (Beta)a;
19. a.foo();  20. b.foo();
21. }
22. }
What is the result?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
E. Compilation fails.
F. An exception is thrown at runtime.

Q. 12 Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized(Thread.currentThreat()) {
10. obj.wait();
11. obj.notify();
12. }
13. }
Which statement is true?
A. This code may throw an interruptedException.
B. This code may throw an illegalstateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this method to complete normally.

Q, 13 Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11. }
Which statement is true?
A. Compilation fails.
B. An exception is thrown at runtime.
C. Synchronizing the run() method would make the class thread-safe.
D. The data in variable “x” are protected from concurrent access problems.
E. Declaring the doThings() method as static would make the class thread-safe.
F. Wrapping the statements within doThings() in a synchronized (new Object()) { } block would make the class thread-safe.

Q. 14 Given:
11. public void testIfA() {
12. if (testlfB(“True”)) {
13. System.out.println(“True”);
14. } else {
15. System.out.println(“Not True”);
16. }
17. }
18. public Boolean testlfB(String str) {
19. return Boolean.valueof(str);
20. }
What is the result when method testlfA is invoked?
A. True
B. Not True
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12
E. Compilation fails because of an error at line 13.

Q. 15 when comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?
A. closing the stream.
B. flushing the stream
C. writing to the Stream
D. marking a location in the stream
E. writing a line separator to the stream
     
16. The calendar for the year 2007 will be the same for the year.
A. 2014                 B. 2016                       c. 2017                  D. 2018

17. A man standing at a point P is watching the top of a tower, which makes an angle of elevation of 30 degree with the man’s eye. The man walks some distance towards the tower to watch its top and the angle of the elevation becomes 60 degree. What is the distance between the base of the tower and the point P?
A. 43 units           B. 8 units              C. 12 units           D. Data inadequate.

18. Two ships are sailing in the sea on the two sides of a lighthouse. The angle of elevation of the top of the lighthouse is observed from the ships are 30 degree and 45 degree respectively. If the lighthouse is 100 m high, the distance between the two ships is:
A. 173 m               B. 200 m               C. 273 m               D. 300 m

19. A and B take part in 100 m race. A runs at 5 kmph. A gives B a start of 8 m and still beats him by 8 seconds. The speed of B is:
A. 5.15 kmph      B. 4.14 kmph      C. 4.25 kmph      D. 4.4 kmph

20. In 100 m race, A covers the distance in 36 seconds and B in 45 seconds. In this race A beats B by:
A. 20 m                 B. 25m                  C. 22.5m               D. 9 m

No comments:

Post a Comment