d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Inheritance Vs. Abstract Class Python > Topic
Add Reply New Topic New Poll
Member
Posts: 1,455
Joined: Jun 2 2013
Gold: 313.33
Jul 15 2015 11:15pm
What is the difference between the two, like a pythonic definition and explanation?

I might post on stackoverflow later if the answers are unclear.

This is my understanding below and if it's wrong, please correct any information. Much appreciated!

1. Inheritance Classes
The Inheritance relationship between two classes exists when you have an object of one class,

and an object of another class that has some characteristic different(modified) from the previous object.

For example, an account with a balance in it and a savings account that accrues interest.

A savings account is an account in its own right, however, the modified part is that it gains interest.

NOTE: Both the account class and savings account class can have objects represented by them. Note that the savings account object has all the properties of an account, obviously. Both are Concrete Classes.

2. Abstract Classes

For an abstract class, you can't refer to it as an object. For example, the class Shape, with its subclasses

rectangle and circle, is abstract. On one side, classes Rectangle and Circle are concrete classes, meaning that you can call on it later

and return a value and such. But the class Shape itself doesn't have a real value to return; hence, it's called an

abstract class because it can't return an actual value.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 16 2015 05:23pm
you phrased your question weird. are you asking for the difference between inheritance and abstract classes or are you asking for the difference between a concrete class and an abstract class?

if the former, inheritance is being able to use functions/properties from super classes into a sub class. that's the relationship between inheritance and classes.

if the latter, you cannot instantiate an instance of an abstract class if you have abstract methods.

i assume you're referring to the abc module.

https://docs.python.org/2/library/abc.html
Member
Posts: 1,455
Joined: Jun 2 2013
Gold: 313.33
Jul 17 2015 12:37pm
Thank you carteblanch; I understand it now.
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Jul 21 2015 09:13am
Inheritance and abstract classes are independent of the programming language.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll