• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritence question  RSS feed

 
Kartik Patel
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please let me know how can I access print method of parent class in folowing code?

public class Temp extends parent{

public void print()
{
System.out.println("here in child");
}
public static void main(String[] args) {
// Add code here
}
}

abstract class parent
{
public void print()
{
System.out.println("here in parent");
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the child class you can call "super.print()" to invoke the parent version of the method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!