SCJP MOCK QUESTIONS - 1

QUESTION

Given:
11. public interface Status {
12. /* insert code here */ int MY_TRUE_VALUE = 10;
13. }
Which three are valid on line 12? (Choose three.)
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected




ANS - ABD

In Interfaces we can define constants for example:

interface you
{ int i=10;
}

now in interfaces every variable is implicitly public static final
Therefore, though we define int i=10 but for the compiler it is
public static final int i=10;

Now you can even define like this way :

  1. final int i=10;
  2. static int i=10;
  3. public int i=10;
  4. public static int i=10;
  5. public final int i=10;
  6. static final int i=10;
  7. public static final int i=10;
All these declarations are valid but for the compiler all these declarartions lead to the same declaration - public static final int i=10;


Invalid Declarations:

native - can be only applied to methods
private - variables in interfaces are public
protected - variables in interfaces are public
abstract - As the variables are implicitly final and we know final and abstract cannot be together, therefore it is invalid.

0 comments:

Post a Comment