Samy
Samy

Reputation: 485

Use of an abstract class in Java

I found this statement in a tutorial: "If a class is abstract and cannot be instantiated, the class does not have much use unless it is SUBCLASS"

This seems wrong. I was wondering if what they really meant was: "If a class is abstract and cannot be instantiated, the class does not have much use unless it is a SUPERCLASS".

Would you agree? Thank you.

Upvotes: 0

Views: 57

Answers (4)

Baltasarq
Baltasarq

Reputation: 12222

I've been reading that tutorial, and that's not the worst sentence to be found. For example:

"Abstraction refers to the ability to make a class abstract in OOP."

In general, the writer of the "tutorial" seems to be walking around all concepts, phrasing sentences he or she found elsewhere, but not really understanding them.

If you are learning object-oriented programming, verifying your sources is a good starting point. The book from Bruce Eckel is recognized as a very good learning resource, and you can buy a copy, donwload the beginning of the book, or download a complete, previous edition:

http://www.mindviewinc.com/Books/TIJ4/PurchaseBook.php

Just reading the free demo will make you more good than that complete "tutorial".

Upvotes: 3

Ferrakkem Bhuiyan
Ferrakkem Bhuiyan

Reputation: 2783

Abstract class

   1.Define structure, identity and some default supported behaviour .
   2. Applicable to show vertical inheritance, i.e. deep branching on the several levels (e.g. AbstractEntity class in domain driven development)
   3. Members can have different visibility (from public to private)
   4. You can implement some members (e.g. *Reader classes)
  5.  Inheritance child can have only one base abstract class

Upvotes: 1

giorashc
giorashc

Reputation: 13713

An Abstract class is a class where its behavior is defined by its subclasses (although a generic behvaior can be defined for the abstract class as a base class).

So if you do not have subclass(es) implementing the behavior then there is really no use for it. (which is reflected by not allowing you to instantiate the abstract class)

"If a class is abstract and cannot be instantiated"

is not a correct statement since an abstract class can never be instantiated.

Upvotes: 0

Eran
Eran

Reputation: 394096

Perhaps what what actually meant was "unless it is SUBCLASSED" (which means that sub-classes of it were created), which makes much more sense.

Upvotes: 2

Related Questions