Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can you override private or static method in Java ?

user-image
Question added by Muhammed Rahshad Koyippalli , Cisco DNAC Senior Escalation Engineer , Cisco Systems - India
Date Posted: 2014/05/24
Mohammed Ameen
by Mohammed Ameen , Java Developer , TATA Consultancy Services Limited (TCSL)

No,Not Possible.

Explanatation:1)STATIC  means one per class,not one for each object no mater how many instances of a class exist.Since OVERRIDING is done based on object ,and also as STATIC METHODS are attached to a CLASS,not to an object,we cannot override STATIC METHODS.

 

2)Anything declared as PRIVATE ,cannot be accessed outside the class,wherein which it has been defined.Since PRIVTE METHODS of SUPER CLASS are not accessible from a SUB CLASS,we cannot override them.

Taiyeb Firfiray
by Taiyeb Firfiray , Trainee , MRMWR

No it is not possible to override a private method because a private method is accessible only in the declared class. Method overriding is to provide a different implementation for the method in the subclass. If a subclass cannot access a method there is no meaning of overriding the method.

Static methods are not overridden but inherited by the subclass. If a static method defined in superclass is redefined in subclass the static method in superclass is hidden.

N0 we cannot override private and static methods in java.....if we want t00verride we firstly changed it into public or protected then we can0verride..

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.