What does the “private” modifier do?

There’s a certain amount of misinformation here: “The default access modifier is not private but internal” Well, that depends on what you’re talking about. For members of a type, it’s private. For top-level types themselves, it’s internal. “Private is only the default for methods on a type” No, it’s the default for all members of … Read more

Change the access modifier of an overridden method in Java?

Java doesn’t let you make the access modifier more restrictive, because that would violate the rule that a subclass instance should be useable in place of a superclass instance. But when it comes to making the access less restrictive… well, perhaps the superclass was written by a different person, and they didn’t anticipate the way … Read more

Error 1 Inconsistent accessibility: return type is less accessible than method

Your Composite class is not public. You can’t return a non-public type from a public method. If you don’t specify an accessibility for a non-nested class then internal is used by default. Add public to your Composite class definition: public class Composite { … Alternatively, if buildComposite doesn’t need to be public (meaning it’s only … Read more

Why can’t my subclass access a protected variable of its superclass, when it’s in a different package?

It works, but only you the children tries to access it own variable, not variable of other instance ( even if it belongs to the same inheritance tree ). See this sample code to understand it better: //in Parent.java package parentpackage; public class Parent { protected String parentVariable = “whatever”;// define protected variable } // … Read more

MVVM: Should a VM object expose an M object directly, or only through getters delegating to M’s getters?

There is not a general agreement about that question. For example it was one of the open questions about MVVM formulated by Ward Bell here: Is the VM allowed to offer the V an unwrapped M-object (e.g., the raw Employee) ? Or must the M-object’s properties (if it is even permitted to have properties!) be … Read more