Java OCA OCP Practice Question 2746

Question

Assuming that the following classes are in the same package, which statements are true?

class Main {/*  www.j a v a  2s .c  om*/
   void method1() { }
   public void method2( { }
   private void method3( { }
   protected void method4() { }
 }

class demo [
   public void someMethod(String[] parameters) {
      Main sc = new Main();
      sc.method1();
      sc.method2();
      sc.method3();
      sc.method41();
   }
}
  • a. sc.method1() will generate a syntax error.
  • b. sc.method2() will generate a syntax error.
  • c. sc.method3() will generate a syntax error.
  • d. sc.method4() will generate a syntax error.
  • e. No syntax errors will be generated.


c

Note

As the classes are on the same package and all of the methods are visible except for the private method.




PreviousNext

Related