faqts : Computers : Programming : Languages : Java

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 12 people (67%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Java: Class: Inheritance: What is inheritance?

May 25th, 2006 16:39
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 27 September 2003 - 05:42 pm ------------------

Java: Class: Inheritance: What is inheritance?

---

The basic idea is that you can 'copy' information (=variables,
functions and procedures) from another class to your current class.

After which you can 'replace', 'add' or 'insert' extra information
(=variables, functions and procedures) to your current class, to
further adapt it to your needs (e.g. reuse, creating classification,
creating hierarchy, ...).

---

Inheritance is the ability for a class or object to be defined as an
extension or specialization of another class or object.

---

A goal of object-oriented programming is to 'reuse' a class that you
created for one applet within another applet, which saves you
programming time.

---

As you define your classes, there may be times when a new class uses
many or all of the features of an existing class, and then adds one or
more data, function or procedure members.

---

In such cases, Java lets you build the new object by extending the
characteristics of the existing object.

---

In other words, the new object will 'inherit' the members
(=variables, functions and procedures) of the existing class (called
the 'super' class).

---

When you extend a new class from an existing class,
the new class is often called a 'subclass'.

---

Note: here 'super' class can also be read as 'parent' class and
'extended' class can also be read as 'child' class.

---

1. Access to 'super' class members:

   When your applets use inheritance, you use a 'super' or 'parent'
   class to derive a new class (or 'child' class), such that the new
   class inherits the 'super' or 'parent' class members (=variables,
   functions and procedures).

2. Use of 'super' class constructors:

   To initialize class members for an extended or 'sub' class, your
   applet must invoke the 'super' class and 'sub' class constructor
   functions.

3. 'Protected' access modifier:

   In addition to the access modifier 'public' (=accessible to all),
   and 'private' (=accessible to class methods), Java provides
   'protected' members, that are accessible by the 'super' and
   extended 'sub' class members.

http://www.faqts.com/knowledge_base/view.phtml/aid/24759/fid/165

4. 'This' and 'super' keyword:

   To resolve name conflicts between a 'super' class and extended
   'sub' clas members, your applet can use the 'this' and 'super'
   keywords.

---

[book: source: Jamsa, Kris - Java Now! - ISBN 1-884133-30-4 - p. 
179 'Understanding inheritance' - 
http://www.amazon.com/exec/obidos/tg/detail/-
/1884133304/qid=1064843888/sr=1-3/ref=sr_1_3/103-6292513-4946208?
v=glance&s=books]

---
---

Internet: see also:

C#: Class: Inheritance: What is inheritance?
http://www.faqts.com/knowledge_base/view.phtml/aid/24870

C++: Class: Inheritance: What is inheritance?
http://www.faqts.com/knowledge_base/view.phtml/aid/24866

Delphi: Class: Inheritance: What is inheritance?
http://www.faqts.com/knowledge_base/view.phtml/aid/24869

Java: Class: Inheritance: Create: Simple: Can you give an example of 
inheritance?
http://www.faqts.com/knowledge_base/view.phtml/aid/24891/fid/165

----------------------------------------------------------------------