Java Programming Questions and Answers Set 23

Java Programming OOPs

Questions 221 to 230



221.
Which of the following statements is/are valid array declarations?
I.     int number();
II.     float average[];
III.    double[] marks;
IV.   counter int[];
V.    []double marks;
(a)
Both (II) and (III) above
(b)
Only (I) above
(c)
Both (I) and (III) above
(d)
Only (IV) above
(e)
Only (V) above.
222.
Consider the following code
int number[] = new int[5]; After execution of this statement, which of the following is/are true?
I.     number[0] is undefined.
II.     number[5] is undefined.
III.    number[4] is null.
IV.   number[2] is 0.
V.    number.length() is 5.
(a)
(II), (IV) and (V) above
(b)
Both (I) and (V) above
(c)
Both (III) and (V) above
(d)
Only (V) above
(e)
All (I), (II), (III), (IV) and (V) above.
223.
What will be the content of array variable table after executing the following code?
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
if(j == i) table[i][j] = 1;
else table[i][j] = 0;
(a)
1 0 0
0 1 0
0 0 1
(b)
0 0 0
0 0 0
0 0 0
(c)
1 0 0
1 1 0
1 1 1
(d)
0 0 1
0 1 0
1 0 0
(e)
0 0 0
0 0 1
1 0 0.
224.
Which of the following statements about abstract methods/classes in Java is/are true?
I.     An abstract class cannot be instantiated.
II.     Constructors cannot be abstract.
III.    A subclass of an abstract class must defined the abstract methods.
IV.   Static methods may be declared abstract.
(a)
Both (I) and (II) above
(b)
(I), (II) and (III) above
(c)
Only (I) above
(d)
Only (II) above
(e)
All (I), (II), (III) and (IV) above.
225.
Which keyword can protect a class in a package from accessibility by the classes outside the package?
(a)
don't use any keyword at all (make it default)
(b)
Private
(c)
Protected
(d)
final
(e)
static.
226.
We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
(a)
Private or protected
(b)
Private
(c)
Protected
(d)
Public    
(e)
Private or public.
227.
The type long can be used to store values in the following range:
(a)
-263 to 263-1
(b)
-231 to 231-1
(c)
-264 to 264
(d)
-232 to 232-1
(e)
232 to 264-1.
228.
Which of the following is/are not hexadecimal numbers?
I.     999.
II.     (hex)23.
III.    0x556.
IV.   0x1F2.
(a)
Both (I) and (II) above
(b)
Only (I) above
(c)
Only (III) above
(d)
(I), (II) and (III) above
(e)
All (I), (II), (III) and (IV) above.
229.
Select the invalid assignment statement(s) from the following:
I.     Float x = 238.88;
II.     Double y = 0x443;
III.    int n = (int) true;
IV.   long m =778645;
(a)
Both (I) and (III) above
(b)
Only (II) above
(c)
Both (II) and (IV) above
(d)
Both (I) and (II) above
(e)
All (I), (II), (III) and (IV) above.
230.
Which of the following expressions will produce errors upon compilation?
I.     boolean a = (boolean) 1;
II.     boolean b = (false && true);
III.    float y = 22.3;
IV.   int x = (25 | 125)
(a)
Both (I) and (III) above
(b)
Only (I) above
(c)
(I), (III) and (IV) above
(d)
(I), (II) and (IV) above
(e)
All (I), (II), (III) and (IV) above.





Answers



221.
Answer : (a)
Reason:  Remaining all are invalid declarations.
222.
Answer : (a)
Reason:  Remaining choices are false
223.
Answer : (a)
Reason:  The content of array variable table after executing the following code is
1 0 0
0 1 0
0 0 1
224.
Answer : (a)
Reason:  Line 1 and line 2 only   
A subclass of an abstract class can also be abstract if it does not define all the abstract methods in the parent class.
225.
Answer : (a)
Reason:  don't use any keyword at all (make it default)
226.
Answer : (a)
Reason:  To make a member of a class visible in all subclasses regardless of what package they are in either private OR protected
227.
Answer : (a)
Reason:  -263 to 263 – 1 The type long is a 64-bit two's complement that can be used for long integers.
228.
Answer : (a)
Reason:  Hexadecimal numbers start with "0x" in the Java programming language.
229.
Answer : (a)
Reason:  238.88 is a double in Java. To assign this value to a float, 238.88f must be used. A variable of type boolean cannot be converted to an integer in Java.
230.
Answer : (a)
Reason:  Integers cannot be converted to booleans, and floats must be explicitly specified (22.3f, and not 22.3 which is a double).
<< 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 >>


1 comment :

  1. in 226 How private member can be accessed outside even a class, you are talking about packages ???

    ReplyDelete