• Post Reply Bookmark Topic Watch Topic
  • New Topic

General Question regardiing access modifiers  RSS feed

 
Fame Devon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a particular condition, just need you help to verify it.

I have 2 packages, packageA and packageB. packageA has 1 default class DefaultClass and 1 public class SubClass. SubClass extends DefaultClass.
DefaultClass has a method public functionA();Now coming to packageB. It has 2 classes AccessorA and AccessorB. AccessorA extends SubClass, therefore it can access the method functionA();Now AccessorB has an instance of SubClass. But I'm not able to access functionA() using that instance.

Now, is this okay, or should I be able to access the functionA(). Because functionA() is in a default class, but it should be passed on to the SubClass. Its a bit confusing, so help me out.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My, that sounds complicated. Have you tried it? I suspect the answer is yes.
You can inherit a public method from a package‑private (=default) class, in a public class in the same package. The public method is now accessible outside the package, but only in the subclass.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something not right about not being able to use that method in the other package. Please show us some code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!