Java Programming Questions and Answers Set 24

Java Programming OOPs

Questions 231 to 240



231.
Which of the following will produce an error?
I.          byte a1 = 2, a2 = 4, a3;
II.         short s = 16;
III.        a2 = s;
IV.       a3 = a1 * a2;
(a)
Both (III) and (IV) above
(b)
Only (II) above
(c)
Only (III) above
(d)
Only (IV) above
(e)
Both (I) and (IV) above.
232.
Examine the following code snippets to identify the legal loop constructs:
I.     for (int i = 22, int j = 0; i + j > 11; i = i-3, j++)
{
... (Other statements)
}
II.     int i = 100;
while(i)
{
... (other statements)
}
III.    while (int i > 0)
{
i--;
... (other statements)
}
IV.   int i = -10, sum = 0;
do {
... (other statements)
}
while(sum < 5 || i < 0);
(a)
Both (I) and (IV) above
(b)
Only (I) above
(c)
Only (II) above
(d)
Both (I) and (III) above
(e)
All (I), (II), (III) and (IV) above.
233.
When we invoke repaint () for a java.awt.Component object, the AWT invokes the method
(a)
Insert()
(b)
update()
(c)
draw()
(d)
show()
(e)
paint().
234.
What does the following line of code do?
Textfield text = new Textfield (10);
(a)
Creates text object that can hold 10 columns of text
(b)
Creates text object that can hold 10 rows of text
(c)
Creates the object text and initializes it with the value 10
(d)
The code is illegal
(e)
Creates text object that can hold 10 columns of text and 10 rows of text.
235.
Which of the following applet tags is legal to embed an applet class named Test into a Web page?
(a)
< applet
code = Test.class width = 200 height = 100>
(b)
< applet
class = Test width = 200 height = 100>
(c)
< applet>
code = Test.class width = 200 height = 100>
(d)
< applet
code = Test.class width = 200 height = 100
(e)
< applet
param = Test.class width = 200 height = 100>.
236.
Which of the following classes are available in the java.lang package?
I.          Stack.
II.         Object.
III.        Math.
IV.       String.
V.        StringBuffer.
Choose the correct option from the following:
(a)
(II), (III), (IV) and (V) above
(b)
(II), (III) and (IV) above
(c)
(II), (IV) and (V) above

(d)
(III), (IV) and (V) above
(e)
All (I), (II), (III), (IV) and (V) above.
237.
Which of the following are the wrapper classes?
I.     Random.
II.     Byte.
III.    Integer.
IV.   Short.
V.    Double.
(a)
(II), (III), (IV) and (V) above
(b)
(II), (III) and (IV) above
(c)
(II), (III) and (V) above
(d)
(III), (IV) and (V) above
(e)
All (I), (II), (III), (IV) and (V) above.
238.
Which of the following contain error?
I.     int x[] = int[10];.
II.     int[] y = new int[5];
III.    x = y = new int[10];
IV.   int a[] = {1, 2}; int b[]; b = a;
V.    int i = new int(10);
(a)
(I), (III) and (V) above
(b)
(I), (III) and (IV) above
(c)
(I), (IV) and (V) above
(d)
(III), (IV) and (V) above
(e)
All (I), (II), (III), (IV) and (V) above.
239.
Which is the latest version of the Java language?
(a)
Java 5.0
(b)
Java 6.0 Alpha
(c)
Java 6.0 Beta
(d)
Java 7.0
(e)
Java 7.0 Beta.
240.
How to declare a class which has fields that are not serializable?
(a)
Public
(b)
Private
(c)
Protected
(d)
Variant
(e)
Transient.

Answers 


231.
Answer : (a)
Reason:  In line 3, a short value is being assigned to a variable of type byte, which is illegal. Also, the "*" operator promotes the bytes to integers, which makes it illegal to assign the return value to a variable of type byte.
232.
Answer : (a)
Reason:  In option (B), the argument of "while" is an integer, which is illegal. It can only be Boolean. In option (C), "int i > 0" is an illegal construct.
233.
Answer : (a)
Reason:  In option (B), the argument of "while" is an integer, which is illegal. It can only be Boolean. In option (C), "int i > 0" is an illegal construct.
234.
Answer : (a)
Reason:  Creates text object that can hold 10 columns of text.
235.
Answer : (c)
Reason:  < applet
Code = Test. class width = 200 height = 100>
236.
Answer : (a)
Reason:  Object, Math, String, String Buffer belong to Java.lang package.1
237.
Answer : (a)
Reason:  Byte, integer, short and double are the wrapper classes.
238.
Answer : (a)
Reason:  Statements (I), (III) and (V) contain error.
239.
Answer : (a)
Reason:  Java 5.0 includes a number of new language features, most notably generic types, which increase both the complexity and the power of the language.
240.
Answer : (e)
Reason:  We can declare them as transient.



<< 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 >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment