logo

CuriousTab

CuriousTab

Discussion


Home Java Programming Declarations and Access Control See What Others Are Saying!
  • Question
  • Which is a valid declaration within an interface?


  • Options
  • A. public static short stop = 23;
  • B. protected short stop = 23;
  • C. transient short stop = 23;
  • D. final void madness(short stop);

  • Correct Answer
  • public static short stop = 23; 

    Explanation
    (A) is valid interface declarations.

    (B) and (C) are incorrect because interface variables cannot be either protected or transient. (D) is incorrect because interface methods cannot be final or static.


    More questions

    • 1. What will be the output of the program (in jdk1.6 or above)?
      public class BoolTest 
      {
          public static void main(String [] args) 
          {
              Boolean b1 = new Boolean("false");
              boolean b2;
              b2 = b1.booleanValue();
              if (!b2) 
              {
                  b2 = true;
                  System.out.print("x ");
              }
              if (b1 & b2) /* Line 13 */
              {
                  System.out.print("y ");
              }
              System.out.println("z");
          }
      }
      

    • Options
    • A. z
    • B. x z