0% found this document useful (0 votes)
3 views1 page

Java Inheritance and Access Modifiers

The document defines four classes - TestSuper, TestSubExternal, TestSub, and SomeExternalPackageClass. TestSuper defines fields with different access modifiers and a constructor that accesses these fields. TestSubExternal and TestSub both extend TestSuper and define their own fields that are accessed in their constructors along with calling the parent constructor. SomeExternalPackageClass creates instances of TestSuper and TestSub to access their public fields while SomePackageClass creates instances without needing to specify the package.

Uploaded by

daenuprobst
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Inheritance and Access Modifiers

The document defines four classes - TestSuper, TestSubExternal, TestSub, and SomeExternalPackageClass. TestSuper defines fields with different access modifiers and a constructor that accesses these fields. TestSubExternal and TestSub both extend TestSuper and define their own fields that are accessed in their constructors along with calling the parent constructor. SomeExternalPackageClass creates instances of TestSuper and TestSub to access their public fields while SomePackageClass creates instances without needing to specify the package.

Uploaded by

daenuprobst
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

myPackage

somePackage

public class TestSuper { private int privateInt; public int publicInt; protected int protectedInt; int noModifierInt; public TestSuper() { [Link]; [Link]; [Link]; [Link]; } }

public class TestSubExternal extends [Link] { private int subExternalPrivateInt; public int subExternalPublicInt; protected int subExternalProtectedInt; int subExternalNoModifierInt; public TestSubExternal() { [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; } }

public class TestSub extends TestSuper { private int subPrivateInt; public int subPublicInt; protected int subProtectedInt; int subNoModifierInt; public TestSub() { [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; } }

public class SomeExternalPackageClass { public SomePackageClass() { [Link] testSuper = new [Link](); [Link]; [Link] testSub = new [Link](); [Link];

private class SomePackageClass { public SomePackageClass() { TestSuper testSuper = new TestSuper(); [Link]; [Link]; [Link]; TestSub testSub = new TestSub(); [Link]; [Link]; [Link]; } }

} }

You might also like