can a static method be overridden

Answers were Sorted based on User's Feedback



can a static method be overridden ..

Answer / lakshmanan n

Static methods can be overriden but why do you want to call
the static methods thro instance of the subclass or super
class.

If it is a static method.

call those methods like the following...

SuperClassName.methodName()
SubClassName.methodName()

Is This Answer Correct ?    2 Yes 3 No

can a static method be overridden ..

Answer / nitasha

Static methods are not overriden, they are hidden by static
method in subclass. Check out the link:

http://www.xyzws.com/javafaq/can-static-methods-be-overridden/1

Is This Answer Correct ?    4 Yes 6 No

can a static method be overridden ..

Answer / nisha

/* STATIC METHODS CANT BE OVERRRIDDEN....*/

class Animal {
static void doStuff() {
System.out.print("a ");
}
}

class Dog extends Animal {
static void dostuff() { // it's a redefinition,
// not an override
System.out.print("d ");
}

public static void main(String [] args) {
// Animal [] a = {new Animal(), new Dog(), new Animal()};
// for(int x = 0; x < a.length; x++)
// a[x].doStuff(); // invoke the static method

dostuff();
Animal a=new Dog();
a.doStuff();
}
}

Is This Answer Correct ?    2 Yes 4 No

can a static method be overridden ..

Answer / sandya

Hi, Narasimha Rao Bodagala
I didnt get u. can u please explain once?

Is This Answer Correct ?    3 Yes 6 No

can a static method be overridden ..

Answer / mohit kaushik

yes main method can be override example

class mad
{
public static void main(String args[])
{}
}
public class mohit extends
{
public static void main(String args[])
{
System.out.println("HELLO");
}}


output HELLO
ANY question contact me with our email.my id.
mohit_kaushik1234@rediff.com

Is This Answer Correct ?    2 Yes 6 No

can a static method be overridden ..

Answer / abid mehmood

An instance method can not override the static method of
its parent class.like
if parenet class contains
public static void test()
{
}
then in child class you can't override like this

public void test(){ //you can't override
}
or even like this

public static int test(){ //compile time error:type is
incompatibe with parent's test method.
}

Is This Answer Correct ?    4 Yes 9 No

can a static method be overridden ..

Answer / karteek

Hi, Srinivas.....in the above program posted by Aswini...I
think main() method is overridden....right?.....then we can
say static methods can be overridden....

Eg:

class Parent
{
public static void myStaticMethod()
{
System.out.println("A");
}

public void myInstanceMethod()
{
System.out.println("B");
}
}

public class Child extends Parent
{
public static void myStaticMethod()
{
System.out.println("C");
}

public void myInstanceMethod()
{
System.out.println("D");
}

public static void main(String[] args)
{
Parent o1 = new Parent();

Child o3 = new Child();

Parent.myStaticMethod(); // A
Child.myStaticMethod(); // C

o1.myStaticMethod(); // A
o1.myInstanceMethod(); // B


o3.myStaticMethod(); // C
o3.myInstanceMethod(); // D


}
}

In the above program myStaticMethod() is
overridden.....which is a static method.....

Is This Answer Correct ?    10 Yes 16 No

can a static method be overridden ..

Answer / mohit

static method can be overriden. that is true

Is This Answer Correct ?    3 Yes 9 No

can a static method be overridden ..

Answer / ravi

any one reply the answer with ex

Is This Answer Correct ?    8 Yes 23 No

can a static method be overridden ..

Answer / gaythri

static method can be overridden

Is This Answer Correct ?    15 Yes 43 No

Post New Answer

More Advanced Java Interview Questions

What is the name of the state, when a thread is executing?

4 Answers  


What are the sequence of steps to write pub or sub model kind of application?

0 Answers   TCS,


If i learn Java, what kind of applications can i create that will help Banking, Retail, Hotel, Logistics industry.

2 Answers  


Define prototype?

0 Answers  


What class is used to create Server side object ?

0 Answers  






the same information whether it will connect to the database or it will be used previous information?

0 Answers  


How to determine applet?s height and width?

1 Answers  


Explain Object Serialization and it can be used?

3 Answers   Infosys,


whats is mean by jndi

4 Answers   SolutionNET,


1) what is synchronization? 2)write a program to show synchronization ? 3) what is orm? 4) what is getTemplete method and hw u use it? 5)write a singleton program ? 6) what is IOC concept & explain it? 7) methods of spring? 8)explain spring framework? 9)what are the oops concept? 10)what r the diff types of exception? 11)what is AOP(assepct oriented programing)? 12)jsp life cycle? 13)servlet life cycle? 14)how to u catch ur exception when executing a query in hibernate? 15)write javascript function? 16)write a querry to join two tables? 17)wap to show inheritance and use of interface? 18)explain the project? 19)in spring bean class uses singleton or prototype? 20)Explain prototype?

1 Answers   Cap Gemini,


How many ways can a thread be used?

4 Answers   Sun Microsystems,


1) Scenario: I developed my application on local system and everything is perfect and tested. Now on UAT this application is deployed on clustered server environment. They are logical or physically clustered. But application is not working over there. &#61656; What is the issue with application? &#61656; What are the first things which come in your mind?

1 Answers   L&T,


Categories