Declaration and Access Control in Java

Programming Language > Java Programming Language

Evaluate your knowledge of Java declaration and access control with these multiple choice questions. Learn about the different access modifiers and how to declare variables and methods in Java. Take the quiz now! ➲ Declaration and Access Control in Java - Quiz


  • A void add(Integer... args){}
  • B static void add(int... args, int y){}
  • C static void add(int args...){}
  • D static void add(int...args){}
  • A Compile error at line 1 (static x must be only accessed inside static methods)
  • B Compile error at line 2 (constructors can't be static)
  • C Compile error at line 3 (static methods can't invoke this)
  • D Compile error at line 4 (invalid argument type for method main )
  • A Compile error at line 1 (static x must be only accessed inside static methods)
  • B Compile error at line 3 (static methods can't make reference to non-static variables)
  • C Compile error at line 4 (invalid argument type for method main)
  • D Compile error at line 2 (must access x by writing Tester.x)
  • A This method is only accessible from inside the class itself and from inside all subclasses.
  • B In a class, you cannot declare methods with a lower visibility than the visibility of the class in which it is defined.
  • C From within protected methods you do not have access to public methods.
  • D This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.
  • A At Compile-time
  • B At run-time
  • C Depends on the code
  • D None of these
  • A An object of B contains data fields i, j, k, m.
  • B An object of B contains data fields j, k, m.
  • C An object of B contains data fields j, m.
  • D An object of B contains data fields k, m.
  • A Classes
  • B Interfaces
  • C Editing tools
  • D Classes and Interfaces
  • A Declare the method with the keyword public.
  • B Declare the method with the keyword private.
  • C Declare the method with the keyword protected.
  • D Do not declare the method with any accessibility modifiers.
  • A The program has a compilation error because it does not have a main method.
  • B The program will compile, but we cannot create an object of Circle with a specified radius. The object will always have radius 0.
  • C The program has a compilation error because we cannot assign radius to radius.
  • D The program does not compile because Circle does not have a default constructor.
  • A one
  • B two
  • C Compile error - char can't be permitted in switch statement.
  • D Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted.
  • A The will compile successfully and display 9 as output.
  • B The program will lead to compilation error.
  • C The program will lead to runtime error.
  • D The program will compile successfully and display 10 as output.
  • A Only the Test class.
  • B Any class.
  • C Any class in com.mypackage package.
  • D Any class that extends Test.