class Parent
{
static void show()
{
System.out.println("static show in Parent");
}
void show1()
{
System.out.println("Parent show1");
}
}
class Child extends Parent
{
static void show()
{
System.out.println("static show in Child");
}
void show1()
{
System.out.println("Child show1");
}
public static void main(String rk[])
{
Parent p = new Child();
p.show();
p.show1();
}
}
Predict the output and draw a conclusion from that regarding the invocation of static and non-static methods.
{
static void show()
{
System.out.println("static show in Parent");
}
void show1()
{
System.out.println("Parent show1");
}
}
class Child extends Parent
{
static void show()
{
System.out.println("static show in Child");
}
void show1()
{
System.out.println("Child show1");
}
public static void main(String rk[])
{
Parent p = new Child();
p.show();
p.show1();
}
}
Predict the output and draw a conclusion from that regarding the invocation of static and non-static methods.
output:static show in Parent
ReplyDeleteChild show1
conclusion:static method show() in child class is overriden by the show() method in parent class:while non static method show1() in child class can't be overriden by the
method show1() in parent class:::::: it conclude that only static method can be overriden and not the non-static methods or members.
Output will be a compile time error
Delete..show method being overrided ...and its a static method ...abd static method can not be override.....
This comment has been removed by the author.
ReplyDeleteGood Post! Thank you so much for sharing the post, it was so good to read and useful to improve
ReplyDeleteJava Training in Electronic City
Good Post! Thank you so much for sharing the nice post, it was so good to read and useful to improve
ReplyDeleteJava Training in Electronic City