In Inheritance concept, i have a static method in super class and i am inheriting that class to one sub class. In that case the static method is inherited to sub class or not?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the method is public static or protected static in the superclass it will be accessible in the subclass. So in that sense it is inherited. The code below will compile and run fine.
However, this is a bad use of the term “inherited” as it is not tied to a particular instance – hence Kaleb’s answer. Normal OO design does not treat static methods as inherited, and it gets very confusing, especially when you start talking about overriding them.