ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Can you override private or static method in Java ?

user-image
تم إضافة السؤال من قبل Muhammed Rahshad Koyippalli , Cisco DNAC Senior Escalation Engineer , Cisco Systems - India
تاريخ النشر: 2014/05/24
Mohammed Ameen
من قبل 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
من قبل 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.

Rabia Saeed
من قبل Rabia Saeed

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..

المزيد من الأسئلة المماثلة