Johannes
Johannes

Reputation: 225

classes which are not part of the public API

How do I protect classes which are used in another package (from classes which don't inherit) to be instantiated from the outside? Is this even possible in Java?

Upvotes: 0

Views: 158

Answers (2)

Morteza Adi
Morteza Adi

Reputation: 2473

make constructor protected

public class ProtectClass {

    protected ProtectClass() {
        // TODO Auto-generated constructor stub
    }
}

Upvotes: 1

Andy Harris
Andy Harris

Reputation: 938

Well, abstract classes can't be instantiated, but that may not be what you're looking for... I've never heard of this being possible.

Upvotes: 0

Related Questions