Answer Posted / vinay
Making things more clear, how static and non-static method
behaves
public class Super
{
public static void m1()
{
System.out.println("superclass static ");
}
public void m2()
{
System.out.println("superclass nonstatic ");
}
}
public class Sub extends Super
{
public static void main(String args[])
{
Super superWalaObj = new Sub();
superWalaObj.m1();
superWalaObj.m2();
Sub subWalaObj = new Sub();
subWalaObj.m1();
subWalaObj.m2();
}
public static void m1()
{
System.out.println("subclass static ");
}
public void m2()
{
System.out.println("subclass nonstatic ");
}
}
Result:
superclass static
subclass nonstatic
subclass static
subclass nonstatic
Note: The first output is not "subclass static" as with non
static methods.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which javutil classes and interfaces support event handling?
What is the difference between the string and stringbuffer classes?
A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions
What is the argument type of a programs main() method?
What modifiers may be used with an interface declaration?
Why does the tag url-encode javascript and mailto links?
What are the different algorithms used for clustering?
Is jvm a overhead?
What is the difference between a static and a non-static inner class?
Why is string immutable in java?
Is it possible to stop the execution of a method before completion in a sessionbean?
How primary key is implemented in Oracle?
How to pass parameters in RMI?
Explain about local interfaces.
What is the relation between the infobus and rmi?