• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract classes?  RSS feed

 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anyone recommend any tutorials for abstract classes? I'm learning about them now but am confused. Most of the definitions I come across are "abstract classes are used to make something abstract." Oook.
I've looked on sites like oracle and typed it in on google. Even videos I see on YouTube don't really seem to understand it.

Thanks for any tips.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to refer you to the Oracle tutorial, but it leads with "An abstract class is a class that is declared abstract".

Do you understand what a concrete class is? Let's start there. A concrete class is a non-abstract class . (sorry couldn't resist.) Seriously, a concrete class is one that can be instantiated. For example, new MyConcreteClass().

An abstract class is one that is not allowed to be instantiated. This is useful if you want to put some common code that subclasses need to share, but doesn't stand alone. For example,



In this example, it doesn't make sense to create an AbstractShape on its own. But it does make sense to create a Square. Make sense? If not, what part is puzzling?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does your non-abstract method drawLine() have no method body?... you should be teaching your students the correct thing Jeanne
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have explained on numerous occasions that abstraction is just a concept which can be transferred to code... It has to do with taking away all irrelevant aspects of an entity and only focusing on the relevant... Its as if I told you go get my cell-phone on my office table, you immediately know what to go and look for without me saying if its an android or iPhone or something specific... that's because the word is abstract enough holding the meaning of what a cell-phone would be like... Now when you arrive at the table you realize that there is both an android and an iPhone so you become confuse and now ask the question which one... This is the same idea that is transferred to creating abstract classes...



Now you can simulate the same concept drawn in the following class:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:Why does your non-abstract method drawLine() have no method body?... You should be teaching your students the correct thing Jeanne

Because I didn't compile the code and careless error. Fixed; thanks for pointing that out.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!