Java Programming Questions & Answers: part7



Software Programming : Java Programming QUESTIONS AND ANSWERS :: part7 : 1 to 5

Following Software Programming language Entrance Multiple choice objective type questions and answers will help you in Software Programming 2024 examinations :

1.Which statement is true about accessibility of members?

Private members are always accessible from within the same package
Private members can only be accessed by code from within the class of the member
A member with default accessibility can be accessed by any subclass of the class in which it is defined
Private members cannot be accessed at all
Package/default accessibility for a member can be declared using the keyword default.

2.What, if anything, is wrong with following code? void test(int x) { switch (x) { case 1: case 2: case 0: default: case 4: } }

The variable x does not have the right type for a switch expression
The case label 0 must precede case label 1
Each case section must end with a break statement
The default label must be the last label in the switch statement
There is nothing wrong with the code.

3.What will be the result of attempting to compile and run the following code? class MyClass { public static void main(String[] args) { boolean b = false; int i = 1; do { i++; b = !b; } while (opt2); System.out.println(i); } }

The code will fail to compile, since b is an invalid conditional expression in the
ile statement
The code will fail to compile, since the assignment b = !b is not allowed
The code will compile without error and will print 1 when run
ode will compile without error and will print 2 when run

4.Which of the following is true about the use of modifiers?

If no accessibility modifier (public, protected, and private) is specified for a member declaration, the member is only accessible for classes in the package of its class and subclasses of its class anywhere
You cannot specify accessibility of local variables. They are only accessible within the block in which they are declared
Subclasses of a class must reside in the same package as the class they extend
Local variables can be declared static
None of the above.

5.Which of these combinations of switch expression types and case label value types are legal within a switch statement?

switch expression of type int and case label value of type char
switch expression of type float and case label value of type int
switch expression of type byte and case label value of type float
switch expression of type char and case label value of type long
switch expression of type boolean and case label value of type boolean.

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
Trust because you are willing to accept the risk, not because it’s safe or certain