A5 ◦ Access Modifiers

Create a directory named a5 in your assignments directory with the following classes.

Create a class named Foo that satisfies the following specifications:

  • The class is in the assignments.a5 package.
  • The class has a constructor with no parameters.
  • The class has a private method named foo1 that simple prints “private foo1”.
  • The class has a protected method named foo2 that simple prints “protected foo2”.
  • The class has a public method named foo3 that simple prints “public foo3”.
  • The class has a method with no access modifier named foo4 that simple prints “foo4”.

Create a class named Bar that satisfies the following specifications:

  • The class is in the assignments.a5 package.
  • The class extends Foo.
  • The class has a constructor with no parameters. Inside this constructor, attempt to call foo1, foo2, foo3, and foo4.  Please comment out the calls that will not compile due to access restrictions.
  • The class has a private method named bar1 that simple prints “private bar1”.
  • The class has a protected method named bar2 that simple prints “protected bar2”.
  • The class has a public method named bar3 that simple prints “public bar3”.
  • The class has a method with no access modifier named bar4 that simple prints “bar4”.

Create a driver named Test that satisfies the following specifications:

  • The class creates an instance of Bar and on that instance attempts to call foo1, foo2, foo3, foo4, bar1, bar2, bar3, and bar4.  Please comment out the calls that will not compile due to access restrictions.

Compile all of the source code and test it.

Push your code to GitHub.

About the author