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 are the different approaches to represent an inheritance hierarchy?
What are the different types of exception?
Why are my checkboxes not being set from on to off?
Why are component architectures useful?
What is the infobus?
Can I have an action without a form?
what is handle?
What is glasgow?
What are callback interfaces?
the same information whether it will connect to the database or it will be used previous information?
what are getters and setters in Java with examples?
What do you know about seam?
What are externizable interface?
What is Remote Server?
Write a singleton program?