Java Programming Questions and Answers Set 21

Java Programming OOPs

Questions 201 to 210



201.
Every event object has the ________ method.
(a)
getSource()
(b)
getActionCommand()
(c)
getTimeStamp()
(d)
getWhen()
(e)
getKeyChar().
202.
Analyze the following code:
public class Test {
   public static void main(String[] args) {
     String s = new String("Welcome to Java");
     Object o = s;
     String d = (String)o;
   }
}
(a)
When assigning s to o in Object o = s, a new object is created
(b)
When casting o to s in String d = (String)o, a new object is created
(c)
When casting o to s in String d = (String)o, the contents of o is changed
(d)
s, o, and d reference the same String object
(e)
s,o,and d doesnot reference the same String object.
203.
Analyze the following code:
public class Test {
   int x;
   { x++; }
}
(a)
The program cannot be compiled, because the statement x++ must be placed inside a method or a constructor
(b)
You cannot construct an instance of Test, because it does not have a constructor
(c)
When you construct an instance of Test, the value of x becomes 0;
(d)
When you construct an instance of Test, the value of x becomes 1;
(e)
When you contruct an instance of Test the value of x become -1.
204.
The code causes Java to throw
int number = Integer.MAX_VALUE + 1;
(a)
RuntimeException
(b)
Exception
(c)
Error
(d)
Throwable.
(e)
No exceptions.
205.
After Analyzing the following code, which statement is appropriate?
class Test {
   public static void main(String[] args)
     throws MyException {
     System.out.println("Welcome to Java");
   }
}

class MyException extends Error {
}
(a)
You should not declare a class that extends Error, because Error raises a fatal error that terminates the program
(b)
You cannot declare an exception in the main method
(c)
You declared an exception in the main method, but you did not throw it

(d)
The program has a compilation error
(e)
You can declare a class that extends error.
206.
What is the output for y?
int y = 0;
for (int i = 0; i<10; ++i) {
   y += i;
}
System.out.println(y);
(a)
10
(b)
11
(c)
12
(d)
13
(e)
45.
207.
What will be the value of i for the following loop?
int y = 0;
for (int i = 0; i<10; ++i) {
   y += i;
}
(a)
  9
(b)
10
(c)
11
(d)
12
(e)
Undefined.
208.
Which of the following provides the naming services for the server to register the object and for the client to locate the object?
(a)
Server object interface
(b)
Server implementation
(c)
RMI Registry
(d)
Server stub
(e)
Server Skeleton.
209.
Which of the following statement is not defined in the Object class?
(a)
sleep(long milliseconds)
(b)
wait()
(c)
notify()
(d)
notifyAll()
(e)
toString().
210.
Which of the following method is a static in java.lang.Thread?
(a)
run()
(b)
sleep(long)
(c)
start()
(d)
join()
(e)
setPriority(int).

Answers


201.
Answer : (a)
Reason:  Every event object is a subclass of EventObject, which contains the getSource() method.
202.
Answer : (d)
Reason:  Casting object reference variable does not affect the contents of the object.
203.
Answer : (d)
Reason:  x++ is in an initialization block. It is invoked when any constructor of the class is invoked.
204.
Answer : (e)
Reason:  At present, Java does not throw integer overflow exceptions. The future version of Java may fix this problem to throw an over flow exception.
205.
Answer : (a)
Reason:  When an exception of Error type occurs, your program would terminate. Therefore, you should not declare an exception that extends Error.
206.
Answer : (e)
Reason:  Your answer D is incorrect
y should be 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
207.
Answer : (e)
Reason:  The scope of i is inside the loop. After the loop, i is not defined.
208.
Answer : (c)
Reason:  The RMI registry provides the naming services for the server to register the object and for the client to locate the object.
209.
Answer : (a)
Reason:  Remaining other statements are defined in the object class.
210.
Answer : (b)
Reason:  B is the apt choice.


<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


3 comments :

  1. Excellent post!!! Your article helped to under the future of java development. Being an open source platform, java is integrated in most of the software development industries to create rich featured applications. Java Course in Chennai | Best JAVA Training in Chennai

    ReplyDelete