0% found this document useful (0 votes)
7 views2 pages

9 Java

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

9 Java

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

OOP CONCEPTS:

[Link]:

>a class can be defined as "subclass" of another class("superclass").

•SUBCLASS:
-Inherits:
all attributes of superclass
all methods of superclass
all associations of superclass

-can Add new functionality.

-can Use inherited functionality.

-can Override inherited functionality.

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

>Declaration: (keyword "extends")

------------------------------------
public class Person
{
private String name;
private int age;
}
------------------------------------
public class Employee extends Person
{
private int employeeID;
private int salary;
}
------------------------------------
-in MAIN method: (SUBCLASS references)

Employee employee1 = new Employee("John", 35, 253, 1600)

----------------------------------------------------------------------------------
-->if inheritance is not defined, the class extends the class "Object".
----------------------------------------------------------------------------------

•Inheritance Hierarchy:
>java class can have only one SUPERCLASS.
>java class can have an unlimited number of SUBCLASSES.

>there is no limit to the depth of the class tree.

>higher classes are more general and abstract.


>lower classes are more specific and concrete.

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

•Constructors in Inheritance:

>SUPERCLASS constractors must be called in the 1st line of constructor code.

>the keyword "super" calls the SUPERCLASS constructors(like "this" keyword).


-------------------------------------------------------------
//constructor of subclass Employee:
public Employee(String name, int age, int employeeID, salary)
{
super(name, age);
[Link] = employeeID;
[Link] = salary;
}
--------------------------------------------------------------

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

•Method Overriding:
when the implimentation of the method in SUPERCLASS does not provide the
functionality required in the SUBCLASS.

>the method in SUBCLASS must have the same signature as in the SUPERCLASS.
-> same method name + same parameters : change the content.

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

•Object References:
inheritance defines "a kind of" relationship.

->SUPERCLASS references: refer to any SUBCLASS object derived from SUPERCLASS.

Person P1 = new Employee ("Amy", 28, 487, 2000);


| |
SUPERCLASS SUBCLASS

You might also like