Class inheritance: Function is inaccessible

You want public inheritance: class Weapon : Shopable should be: class Weapon : public Shopable Also, names like _SHOPABLE_H_ are illegal in user written C++ code, as they are reserved for the C++ implementation. Forget the leading underscores and use SHOPABLE_H. And: Weapon(int Cost,int Damage,std::string Name) should be: Weapon(int Cost,int Damage, const std::string & Name … Read more

Java tutorial says I can have a package-private interface, but I can’t

It’s the interface itself that can be package-private, not the methods in it. You can define an interface that can only be used (by name) within the package it’s defined in, but its methods are public like all interface methods. If a class implements that interface, the methods it defines must be public. The key … Read more

Why make private inner class member public in Java?

If the InnerEvenIterator class does not extend any class or implement any interface, I think it is nonsense because no other class can access any instance of it. However, if it extends or implements any other non private class or interface, it makes sense. An example: interface EvenIterator { public boolean hasNext(); } public class … Read more

What are the differences between “private”, “public”, and “protected methods”?

Public – can be called from anywhere Private – The method cannot be called outside class scope. The object can only send the message to itself ex: the baker has bake method as public but break_eggs is private Protected – You can call an object’s protected methods as long as the default object self is … Read more