Can we override static methods?

Answer Posted / manikandan [ gtec,vellore ]

Dear yogesh, overriding is not a compile time polymorphism
so u have to run the code.

static methods can't override
pls run below example

class test extends a
{
public static void main(String[]asd)
{
a as=new test();
as.a();//it'll not invoke a() from class test
}
static void a()
{
System.out.println("test");
}
}
class a
{
static void a()
{
System.out.println("a");
}
}

out put: a

as.a(); this line'll not invoke the method a()from class
test instead it'll invoke a a()method from class a so there
is no overriding.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is r * in math?

539


Differentiate between stringbuffer and string?

586


What are the types of methodology?

499


What is the do while loop syntax?

546


What is the use of string and stringbuffer?

538






Can we write class inside a class in java?

540


What do you mean by light weight and heavy weight components?

547


Can we extend immutable class?

521


What are peerless components?

611


What is java in simple terms?

544


What is java volatile?

530


What is codebase?

522


What is the difference between the ">>" and " >>>" operators in java?

499


What is serialization in java?

553


Explain the features of interfaces in java?

547