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
Can I extend singleton class in java?
what is nested class in java?
What is the difference between static and global variables and also define what are volatile variables?
How will you communicate between two applets?
Where will it be used?
What is difference between null and void?
What is the purpose of static keyword in java?
What is downcasting?
How do you check whether the list is empty or not in java?
What is an array length?
What is difference between protected and private?
When throws keyword is used?
What is a substitution variable?
Can we have try without catch block?
I want to store more than 10 objects in a remote server? Which methodology will follow?