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
How would you create a button with rounded edges?
Which characters may be used as the second character of an identifier, but not as the first character of an identifier?
What is the map interface?
Where we can write Rmi registry in the code, without having to write it at the command prompt?
When is the best time to validate input?
what are the activation groupworks?
What happens when a thread cannot acquire a lock on an object?
Which javutil classes and interfaces support event handling?
What are local interfaces? Describe.
Is infobus easy to use?
What is the difference between system.out ,system.err and system.in?
What is the argument type of a programs main() method?
What class is used to create Server side object ?
What is the purpose of the notifyall() method?
Do I need to import javlang package any time? Why ?