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
Is set sorted in java?
What language is pass by reference?
Can you explain the usages of class.forname()?
What is a java lambda expression?
How do you sort arraylist in descending order?
What are the advantages of inner classes?
What is the difference between checked exception and unchecked exception?
What is string substring?
Why set do not allow duplicates in java?
What is an empty class? What functionality does it offer in Java?
What is supplier in java?
Can we write a class without main method in java?
What is collection class in java?
State differences between C and Java?
Is node a data type in java?