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
Why use a datasource when you can directly specify a connection details?
What state does a thread enter when it terminates its processing?
cud u help me ... i am struggling with this question... to find all the subsets of a given set for ex.... a,,b,c shud give all the subsets.... i gt the program in c bt nt able to get it in java..... help needed ..
What is the map interface?
int x=5,i=1,y=0; while(i<=5) { y=x++ + ++x; i=i+2; } System.out.println(x); System.out.println(y); System.out.println(i); How to solve this? Please explain!
How are the elements of a borderlayout organized?
What is bean? Where can it be used?
Explain about local interfaces.
What are the call back methods in entity bean?
What is the difference between RMI registry and OS Agent?
What do you need to set-up a cluster with jboss?
Is infobus easy to use?
How can I avoid validating a form before data is entered?
Explain the steps in details to load the server object dynamically?
What is jboss?