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 JTS?
Should synchronization primitives be used on bean methods?
What is a modular application? What does module-relative mean?
which book is better for jdbc ,servlets and jsp
What happens when a thread cannot acquire a lock on an object?
Which are the different segments of memory?
Which component handles cluster communication in jboss?
Define prototype?
What is metaspace?
how do you Handle Front End Application data against DB with example?
What is an abstract method?
What method is invoked to cause an object to begin executing as a separate thread?
What is colon_pkg_prefixes and what is its use?
In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?
What is ioc concept?