0

I have seen two ways to draw from another class.

First and more simply:

"public class apples extends tuna{"

And another method which looks like:

tuna tunaObject = new tuna ():
tunaObject.test();

As far as I know these two lines do the same thing and they draw from another class. The second way just seems way harder than it has to be.

Bacteria
  • 8,406
  • 10
  • 50
  • 67
Kevin Hodges
  • 55
  • 2
  • 9
  • No they don't do the same thing, not even close. The scope of this question is a bit broad and likely too broad for this site. It's essentially a "please explain inheritance vs. composition to me" type question. Closing as a duplicate, but if you have further questions, please read up in your book or tutorial chapter on Java inheritance and also on composition. – Hovercraft Full Of Eels Jun 21 '15 at 20:15
  • So they do not do the same thing and I need to look into knowing the difference. Thanks. – Kevin Hodges Jun 21 '15 at 20:27
  • The first -- `class Foo extends Bar` uses inheritance, to give Foo Bar properties while `Bar bar = new Bar()` creates a new Bar object and assigns it to a bar variable. Again these are core Java concepts that you're not going to learn here. Again, study your texts as it's all fully explained there. – Hovercraft Full Of Eels Jun 21 '15 at 20:38
  • An elephant is made of (I.e. is composed of) a trunk, 4 legs, a tail etc. An elephant is a specialisation (I.e extends) mammal which extends animal – Richard Tingle Jun 21 '15 at 21:18
  • Thanks. Very helpful info :) – Kevin Hodges Jun 22 '15 at 22:37

0 Answers0