Can you please help me how to create a class which is not inheritable and should be static in behavior (Means we should not be able to create instance of it). I need this class to store constant values. Thanks.
public final class MyClass {
private MyClass() { }
}
The final
keyword makes it not inheritable, and making the constructor(s) private
will help stopping it from being instantiated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With