Saturday, 9 March 2013

MCQ #5

Question) In switch construct , the default statement must be placed after all the case statements.

Options)

  • True
  • False
Answer) False

Explanation) Go through the Java tutorial on switch statement to know more about switch statement and it's usage.As for our question, default statement can be put anywhere in the switch construct but it will be called only when none of the other cases match. Also since default statement is the last one to be checked we need not even write break statement in default statement.So the answer is clearly False.

MCQ #4

Question) Member (instance) variables are always assigned a default value if not explicitly initialized.

Options)

  • True
  • False
Answer) True

Explanation) Go through the Java tutorial on Objects in java to know the difference between instance variables and local variables.As for our question, yes instance variables are assigned default values if not explicitly initialized.On the other hand compiler will complaint if local variables are used without initialization.

MCQ #3

Question)Assume x = 6 and y = 7 .What is the result of (!(y == x))

Options)

  • True
  • False
Answer) True

Explanation) The answer is pretty straight forward . x=6  and y=7 so y == x is false. Negation ( ! ) of false is true and hence our final result is True. Remember brackets have higher preference than any of the operators.

MCQ #2

Question) Using a break in a for loop causes the loop to break out of the current execution and jump to next iteration.

Options)
  • True
  • False
Answer) Flase

Explanation) I would recommend go through the post on Transfer Statements in Java Tutorials section.break keyword will cause loop to break out of current execution permanently and continue with the code after the loop.Note that break statement is used only in loops and switch statement.So answer is False.

MCQ #1

Question) Methods which are marked protected can be accessed only by classes within the same package

Options)
  • True
  • False
Answer) Flase

Explanation) I would recommend go through the post on Access Modifiers in Java Tutorials section.If a member (be it a member variable or a member function) is defined to be protected then it is accessible by members in same class, in same package and also in all the sub classes of class in which the protected member is defined. So it is not just the same package.Hence answer is False.
t> UA-39527780-1 back to top