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
What is a clone?
What is colon_pkg_prefixes and what is its use?
What is the difference between static and non-static with examples?
AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?
How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!
What is ripple effect?
When a thread blocks on i/o, what state does it enter?
Explain what is orm?
What is the difference between the session.update() method and the session.lock() method?
what are the advantages of JTA over JTS?
Explain how will the struts know which action class to call when you submit a form?
Name the eight primitive java types.
Is it possible to stop the execution of a method before completion in a sessionbean?
What is jboss?
Define the remote object implementation?