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
Is the session factory thread safe?
What are the different approaches to represent an inheritance hierarchy?
If I wanted to use a solarisui for just a jtabbedpane, and the metal ui for everything else, how would I do that?
What is ripple effect?
What are externizable interface?
What is the purpose of the wait(), notify(), and notifyall() methods?
What is a class loader? What are the different class loaders used by jvm?
wahts is mean by dynavalidatorform in struts/
Do you think that java should have had pointers?
When a thread blocks on i/o?
What method is invoked to cause an object to begin executing as a separate thread?
which type of objects reference will be given to client?
Why a component architecture for the java platform?
How a component can be placed on Windows?
Why is actionform a base class rather than an interface?