MainMenu

Home Java Overview Maven Tutorials

Sunday, 15 January 2017

Inheritance in java with example



Inheritance in java with example

For Video : CLICK HERE



As like Overloading, Inheritance is also a OOPs feature, Inheritance provide a mechanism that allow a class to inherit property of another class.



When a class inherit another class using extends keywords then all non-private members including fields and Methods.
In java inheritance cab be described in parent, child relationship also known as Super Class(Parent) and Sub class(child) in java language.

Syntax:
Class Parent
{
..............
}
Class Child extends Parent
{
...............
}
Example : In below example parent class has a method witch will be inherited by child and then object of class child will access the methods
package chandan_test1;
class C_parent
{
int x;
public void sum(int a, int b)
{
x = a+b;
System.out.println("Your sum is :" +x);
}
}
public class C_inhritance extends C_parent
{
public void sub(int c, int d)
{
x = d-c;
System.out.println("Your Difference is :" +x);
}
public static void main(String args[])
{
int a = 10;
int b = 20;
C_inhritance alpha = new C_inhritance();
alpha.sum(a,b);
alpha.sub(a,b);
}
}
Output:
Your sum is : 30
Your Difference is : 10

Tags :What is inheritance in Java?,java inheritance with example



22 comments:

  1. Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. The online selenium training course is becoming very popular and its popularity will continue to grow. The point that every sphere of work and business is now being digitalized, the demands of such training continue to soar. Online Advanced JAVA Training

    ReplyDelete
  3. It was wondering if I could use this write-up on my other website, I will link it back to your website though.Great Thanks. xenforo.asia

    ReplyDelete
  4. Thank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideas.I will definitely love to read. [REVEALED] THE BEST FREE PRODUCT RESEARCH SPY TOOL 2019 | FACEBOOK MARKETING & SHOPIFY RESEARCH

    ReplyDelete
  5. Computer tutorials that are created using screen capture software are often extremely beneficial to people because they show a working version of the system and users can relate what the video is showing, to what they are physically seeing. click here for how to guides

    ReplyDelete
  6. I don’t think many of websites provide this type of information. yabo

    ReplyDelete
  7. Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. online

    ReplyDelete
  8. I really love your write-ups web design agency guys continue the good work.

    ReplyDelete
  9. If you like the blackberry bold 9700 or even 9000, you may also like the Video Converter Ultimate recommended in this article, which is a very professional tool to help you convert DVD movies, videos to blackberry bold 9700/9000 formats very easily. Then you can watch your favorite movies whenever and wherever. convert youtube to mp3

    ReplyDelete
  10. Nice written!! I have been a big fan of your blogs. thanksbest ad agency showreels

    ReplyDelete
  11. The post is written in very a good manner and it contains many useful information for me. ดูหนัง

    ReplyDelete
  12. All you need is a PC/PC and a solid and quick web association. online learning

    ReplyDelete
  13. Joyfully for all of us, programming information recuperation is truly sufficient and rates are low evaluated, in any event contrasted with their supplement PC record recuperation administrations. LinkedIn Scraper

    ReplyDelete
  14. Instead, when you watch movies online you can experience the same movie on an HD quality picture and dolby surround sound within the comfort of your home by paying just few dollars (much less than what you pay at the theatres). Moreover, when you access the online movie portals, you are even served with additional features apart from the movie. You can even watch latest movie trailers online, star interviews, conduct online bookings and can access the show timings as well. 123movie

    ReplyDelete
  15. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. ดูหนังออนไลน์

    ReplyDelete
  16. I would like to say that this blog really convinced me to do it! Thanks, very good post. cb01

    ReplyDelete
  17. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. ดูหนัง

    ReplyDelete
  18. Best Selection of Dashiki Shirts and Pants.We are retail and wholesale of dashiki shirts. african print

    ReplyDelete
  19. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. get trafficize

    ReplyDelete
  20. When in the creation business, the nature of the item is constantly observed and tried. custom software development

    ReplyDelete