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
What is the meaning of variables in research?
What is methods in java?
What is string example?
What is the difference between a static and a non-static inner class in java programming?
who can i handle multiple client in RMI
In how many ways we can do synchronization in java?
How many bits is a string in java?
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?
What are the important features of Java 11 release?
Is java map thread safe?
Why is singleton not thread safe?
What is the meaning of flag day?
Are private methods final?
How do you remove all elements from an arraylist in java?
What does substring mean?