Upload
carlos-alcivar
View
52
Download
3
Embed Size (px)
Citation preview
Class 7 y 8 Exposure: Group #1 and Group #2
Group #1
INHERITANCE(Herencia) Allows the creation of new classes based on existing classes.
When you inherit from an existing class, we reuse (or inherit ) methods and fields and add new fields and methods to meet the new situation. The existing class is called the super class or base class, or parent class. The new class is called subclass, derived class, or child class.
Inheritance Hierarchy
EXAMPLO
Tipos de herencia
Single inheritance
· A class can inherit from a single Class.
Example: Java, C #
Multiple Inheritance
· A class can inherit from multiple classes .
· Classes form a directed acyclic graph
Examples : Eiffel , C++
Example
1.-
2.-
package herencia;
public class ClaseHeredada {
String Apellido;
public ClaseHeredada(String Dato) {
this.Apellido=Dato;}
}
package herencia;
public class Herencia extends ClaseHeredada{
String Nombre;
public Herencia(String Texto){
super(Texto);
}
public void setPersona(String NombrePer){
this.Nombre=NombrePer+this.Apellido;
}
public String getPersona(){
return Nombre;
}}
Group #2
POLYMORPHISMS Is the ability of a class of objects respond to the same message or event based on the parameters used during its invocation .A polymorphic object is an entity that can hold values of different types during program execution .
Classification
dynamic polymorphism
static polymorphism
public class Articulo { private float precio; public void setPrecio() { precio = 3.50; } public void setPrecio(float nuevoPrecio) { precio = nuevoPrecio; } public void setPrecio(float costo, int porcentajeGanancia) { precio = costo + (costo * porcentajeGanancia); } }