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 tasks priority and how is it used in scheduling?
What is the difference between a menuitem and a checkboxmenuitem?
A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions
how do you Handle Front End Application data against DB with example?
What is Stream Tokenizer?
What is TL and its use?
Define the remote object implementation?
Why use a datasource when you can directly specify a connection details? (in a J2EE application)
How would you detect a keypress in a jcombobox?
What is the difference between static and non-static with examples?
What is aop(assepct oriented programing)?
Name three subclasses of the component class?
Why a component architecture for the java platform?
In our urls and in the text of the buttons we have comma. Its causing an error. Is there a way to change the delimiting character for the menu arguments?
Which class is the immediate superclass of the menucomponent class?