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

Is set sorted in java?

523


What language is pass by reference?

574


Can you explain the usages of class.forname()?

613


What is a java lambda expression?

562


How do you sort arraylist in descending order?

581






What are the advantages of inner classes?

510


What is the difference between checked exception and unchecked exception?

533


What is string substring?

563


Why set do not allow duplicates in java?

585


What is an empty class? What functionality does it offer in Java?

679


What is supplier in java?

563


Can we write a class without main method in java?

487


What is collection class in java?

549


State differences between C and Java?

669


Is node a data type in java?

502