When to extend a class?

0 Austin Elliott · June 7, 2015
When should you extend a class, and when should you just simply create and object?

For example, Bucky extended JFrame, but just created a JLabel object.

Post a Reply


Oldest  Newest  Rating
+1 Sampan Verma · June 8, 2015
For an instance take an example,

We have a class Human. A Human can walk, eat .... We create 2 other classes man and woman.
Both these extend Human Class. So they Human is the parent class of these one. Now man and woman can do all the stuff which a human class can do. But Why? Now man and woman class can have there own methods and variables like women can be mother while man has to be a father (or single). Now if some new species comes out lets say yoman, you will not create the whole yoman and rewrite its features. Rather yoman will be a human so it will only extend the human class and bam! yoman haves all the methods of Human....

And one other thing:- Extending you class and Creating an instance {object you can say} is very different thing.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator