SlideShare a Scribd company logo
1 of 9
Download to read offline
TECHNICAL UNIVERSITY OF MANABÍ
FACULTY OF COMPUTER SYSTEMS
      ENGINEER CAREER


      ENGLISH PROJECT:
       PROGRAMMING 2


            NAME:
     AYALA CARRILLO JUAN
           ALBERTO


           COURSE:


        3 SEMESTER C


        DELIVERY DATE:
         21/ 01/2012
Technical University of

                                Manabi mission:

Being academics, scientists and professionals responsible, humanistic, ethical
and caring, committed to the goals of national development, which contribute
to solving the country's problems as university teaching with research, able to
     generate and apply new knowledge, encouraging the promotion and
    dissemination of knowledge and culture, under the Constitution of the
                             Republic of Ecuador.

                                      visio
                                       n:

    Being university, leader and reference of higher education in Ecuador,
   promoting the creation, development, transmission and dissemination of
     science, technology and culture, social recognition and regional and
                               global projection.




                                 FACULTY OF
                                 COMPUTER

                                     missio
                                       n:

 Being a unit with high academic prestige, efficiency, transparency and quality
in education, organized in their activities, protagonists of regional and national
                                   progress.

                                      visio
                                       n:

Being efficient and innovative professionals in the field of computer science,
with honesty, fairness and solidarity, provide answers to the needs of society
                      by raising their standard of living.
                                Inheritance in java
Introduction

Heredity, understood as a feature of object-oriented programming and more specifically the C
+ +, to define a class by modifying one or more classes and changes usually consist
existentes.Estas add new members (variables or functions), to the class being defined,
although it can redefine variables or class member functions existentes.La and is part of this
process is called base class and the new class that is obtained is called derived class

This in turn may be based on a new class derivation process, thus initiating a class hierarchy.

It is one of the key weapons of OOP. Allows you to create new classes that inherit
characteristics show in previous classes. This greatly facilitates the work that has created
standard classes for all programmers and from them create our own personal lessons. This is
more convenient than having to create our classes from cero.Para a class to inherit the
features of another must use the extends keyword after the class name. A word is followed by
the name of the class whose characteristics are inherited. You can have only one class
inheritance (a class inherits laque is called superclass and inherited class is called subclass).

Example:




The idea of inheritance is to allow 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.

Every time we find the relation "is-a" between two classes, we are in the presence of
inheritance.



The existing class is called the superclass or base class, or parent class.

The new class is called subclass, derived class, or child class.



Through inheritance we can add new fields, and we can add or set methods (override). On
mounting a method is redefining the inherited case.

The process of inheritance is transitive
Types of inheritance



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 + +
Advantage

• Helps programmers code and saving time, since the parent class has been implemented and
verified earlier, deducting only referenced from the derived class to the base class (typically
extends, inherits, subclass or other similar keywords, depending on the language).

• Objects can be constructed from the like. To do this there needs to be a base class (which
can even be part of a broader class hierarchy).

• The derived class inherits the behavior and attributes of the base class, and it is common for
you to add your own behavior or alter the inherited.

• Any class can serve as a base class to create others.



Inheritance and information hiding

In some languages, the designer can define instance variables and methods of the objects of a
class are visible. In C + + and Java this is accomplished with the specifications private,
protected and public. Only variables and defined as public methods on an object will be visible
for all objects. In other languages like Smalltalk, all instance variables are private and all
methods are public.

Depending on the language used, the designer can also control which members of the
superclass are visible in subclasses. In the case of Java and C + + access specifiers (private,
protected, public) of the members of the superclass also affect inheritance:


• Private: no private member of the superclass is visible in the subclass.

• Protected: protected members of the superclass are visible in the subclass, but not visible to
the outside.

• Public: public members of the public remain superclass in the subclass.




APPLICATION EXAMPLE

Consider a simple example of inheritance, for this case we will create a class which is inherit
where the surname and assign another class where the name of an "X" person. First let's look
at the class to inherit:



package inheritance;
ClaseHeredada {public class

    String last;

    public ClaseHeredada (String Data) {

        this.Apellido = data;}

}



Once we have the class that we inherit our class that will contain the name of the "X" and
assign the following code:



package inheritance;

public class extends Inheritance {ClaseHeredada

    String name;

    public Inheritance (String text) {

        super (text);

    }

    public void setPersona (String NombrePer) {

        NombrePer + this.name = this.Apellido;

    }

    getPersona public String () {

        return Name;

    }

}



It extends to indicate that we are inheriting class "ClaseHeredada" where the surname. The
super is to indicate that we are instantiating the class constructor we are inheriting and
methods are getPersona setPersona and with which will capture and take back the name of
the person.



After this process, we now use in our main instantiating class as follows:
public static void main (String [] args) {

        Inheritance Inheritance X = new ("Arias Figueroa");

        X.setPersona ("Kevin Arnold");

        System.out.println (X.getPersona ());

}

Instantiate Class "Inheritance" passing to its constructor the name of the person which will
internally what the upper class "ClaseHeredada", then we assign the name using his method
setPersona and print it using getPersona.

Made this code should print the person's name by concatenating the name of it.

Annexes

Drill

1) Basic example of inheritance in Java. In this case the Citizen class inherits from the Person
class to take and extend functionality.

Human class {

    protected String name;

    protected String name;

    public Human (String name, String name) {

        this.name = name;

        this.apellido = name;

    }

    public String FullName () {

        return this.apellido + "," + this.nombre;

    }

    identifying public String () {

        this.nombreCompleto return ();

    }



}
Citizen class Human extends {

    protected String document;



    public City (String name, String name, String document) {

        super (name, name);

        this.documento = document;

    }



    identifying public String () {

        super.identificacion return () + "document" + this.documento;

    }

}




Inheritance {public class

    public static void main (String args []) {

        Human = new Human ("Emilio", "Rosso");

        Citizen b = new City ("Emilio", "Rosso", "3052454545");

        Human [] arregloDeHumanos;

        arregloDeHumanos.push (a);

        arregloDeHumanos.push (b);

        identificarPolimorfico (arregloDeHumanos);

    }



    public static void identificarPolimorfico (Human [] arregloDeHumanos) {

        for (int i = 0; i <arregloDeHumanos.length; i + +) {
System.out.println ("Identifying" + arregloDeHumanos [i]. Identification ());

         }

     }



}



But besides this compositional technique is possible to think of cases where a class is an
extension of another. That is, a class is like another and also has some sort of characteristic
that distinguishes it. For example we might think of the Employee class and define it as:

class Employee {

     String name;

     int numEmpleado, salary;



     private static int counter = 0;



     Employee (String name, int salary) {

         this.name = name;

         this.sueldo = salary;

         numEmpleado = + + count;

     }



     public void aumentarSueldo (int percentage) {

         salary + = (int) (salary * increase / 100);

     }

    public String toString () {

         return "Num employee" + numEmpleado + "Name:" + name +

               "Salary:" + salary;

     }

}

More Related Content

What's hot

What's hot (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in c++theory
Inheritance in c++theoryInheritance in c++theory
Inheritance in c++theory
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Dr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java InheritanceDr. Rajeshree Khande : Java Inheritance
Dr. Rajeshree Khande : Java Inheritance
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Oop inheritance chapter 3
Oop inheritance chapter 3Oop inheritance chapter 3
Oop inheritance chapter 3
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
inheritance
inheritanceinheritance
inheritance
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 
Inheritance and overriding
Inheritance  and overridingInheritance  and overriding
Inheritance and overriding
 

Viewers also liked

IEEE-MSIT X-quizite 2011. Finals - round 1
IEEE-MSIT X-quizite 2011. Finals - round 1IEEE-MSIT X-quizite 2011. Finals - round 1
IEEE-MSIT X-quizite 2011. Finals - round 1Ashutosh Varma
 
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...Vall d'Hebron Institute of Research (VHIR)
 
IEEE-MSIT X-quizite 2011 (1/4)
IEEE-MSIT  X-quizite 2011 (1/4)IEEE-MSIT  X-quizite 2011 (1/4)
IEEE-MSIT X-quizite 2011 (1/4)Ashutosh Varma
 
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...Vall d'Hebron Institute of Research (VHIR)
 
Homelessness in Billings 2012: Research and Trends
Homelessness in Billings 2012:  Research and TrendsHomelessness in Billings 2012:  Research and Trends
Homelessness in Billings 2012: Research and TrendsWelcomeHomeBillings
 
IEEE-MSIT X-quizite 2011. Finals - round 2
IEEE-MSIT X-quizite 2011. Finals - round 2IEEE-MSIT X-quizite 2011. Finals - round 2
IEEE-MSIT X-quizite 2011. Finals - round 2Ashutosh Varma
 
Michelle2slides
Michelle2slidesMichelle2slides
Michelle2slidesdspeters76
 
A99c92136e05179ebe7fe1b2cf4dce74
A99c92136e05179ebe7fe1b2cf4dce74A99c92136e05179ebe7fe1b2cf4dce74
A99c92136e05179ebe7fe1b2cf4dce74MICHELE SILVA
 
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)Vall d'Hebron Institute of Research (VHIR)
 
Interpretation of sequence variants in the biomedical environment: what shoul...
Interpretation of sequence variants in the biomedical environment: what shoul...Interpretation of sequence variants in the biomedical environment: what shoul...
Interpretation of sequence variants in the biomedical environment: what shoul...Vall d'Hebron Institute of Research (VHIR)
 
Identification of pathological mutations from the single-gene case to exome p...
Identification of pathological mutations from the single-gene case to exome p...Identification of pathological mutations from the single-gene case to exome p...
Identification of pathological mutations from the single-gene case to exome p...Vall d'Hebron Institute of Research (VHIR)
 
Variant calling and how to prioritize somatic mutations and inheritated varia...
Variant calling and how to prioritize somatic mutations and inheritated varia...Variant calling and how to prioritize somatic mutations and inheritated varia...
Variant calling and how to prioritize somatic mutations and inheritated varia...Vall d'Hebron Institute of Research (VHIR)
 
Lessonplan 100512115922-phpapp02 (2)
Lessonplan 100512115922-phpapp02 (2)Lessonplan 100512115922-phpapp02 (2)
Lessonplan 100512115922-phpapp02 (2)Roel Cortez
 

Viewers also liked (20)

Impacte de la sepsia greu a Catalunya
Impacte de la sepsia greu a CatalunyaImpacte de la sepsia greu a Catalunya
Impacte de la sepsia greu a Catalunya
 
IEEE-MSIT X-quizite 2011. Finals - round 1
IEEE-MSIT X-quizite 2011. Finals - round 1IEEE-MSIT X-quizite 2011. Finals - round 1
IEEE-MSIT X-quizite 2011. Finals - round 1
 
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...
Dr. Esteban Domingo: Respuesta del virus de la hepatitis C a inhibidores. Inf...
 
IEEE-MSIT X-quizite 2011 (1/4)
IEEE-MSIT  X-quizite 2011 (1/4)IEEE-MSIT  X-quizite 2011 (1/4)
IEEE-MSIT X-quizite 2011 (1/4)
 
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...
The impact of SSC 2012 on the planning and evaluation of my hospital's perfor...
 
Homelessness in Billings 2012: Research and Trends
Homelessness in Billings 2012:  Research and TrendsHomelessness in Billings 2012:  Research and Trends
Homelessness in Billings 2012: Research and Trends
 
Jayslide
JayslideJayslide
Jayslide
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
IEEE-MSIT X-quizite 2011. Finals - round 2
IEEE-MSIT X-quizite 2011. Finals - round 2IEEE-MSIT X-quizite 2011. Finals - round 2
IEEE-MSIT X-quizite 2011. Finals - round 2
 
Youth Count! 2013
Youth Count! 2013Youth Count! 2013
Youth Count! 2013
 
Michelle2slides
Michelle2slidesMichelle2slides
Michelle2slides
 
Repaso sexto (1)
Repaso sexto (1)Repaso sexto (1)
Repaso sexto (1)
 
A99c92136e05179ebe7fe1b2cf4dce74
A99c92136e05179ebe7fe1b2cf4dce74A99c92136e05179ebe7fe1b2cf4dce74
A99c92136e05179ebe7fe1b2cf4dce74
 
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)
Cytomegalovirus (CMV) in Intensive Care Unit (ICU) patients (David Navarro, PhD)
 
Interpretation of sequence variants in the biomedical environment: what shoul...
Interpretation of sequence variants in the biomedical environment: what shoul...Interpretation of sequence variants in the biomedical environment: what shoul...
Interpretation of sequence variants in the biomedical environment: what shoul...
 
Identification of pathological mutations from the single-gene case to exome p...
Identification of pathological mutations from the single-gene case to exome p...Identification of pathological mutations from the single-gene case to exome p...
Identification of pathological mutations from the single-gene case to exome p...
 
Variant calling and how to prioritize somatic mutations and inheritated varia...
Variant calling and how to prioritize somatic mutations and inheritated varia...Variant calling and how to prioritize somatic mutations and inheritated varia...
Variant calling and how to prioritize somatic mutations and inheritated varia...
 
C Is Easy
C Is EasyC Is Easy
C Is Easy
 
Encondromatosis
EncondromatosisEncondromatosis
Encondromatosis
 
Lessonplan 100512115922-phpapp02 (2)
Lessonplan 100512115922-phpapp02 (2)Lessonplan 100512115922-phpapp02 (2)
Lessonplan 100512115922-phpapp02 (2)
 

Similar to Segundo avance

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javachauhankapil
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptRithwikRanjan
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Alena Holligan
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 
Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsBharat Kalia
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principlesmaznabili
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloadingDrRajeshreeKhande
 

Similar to Segundo avance (20)

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Oops
OopsOops
Oops
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
java part 1 computer science.pptx
java part 1 computer science.pptxjava part 1 computer science.pptx
java part 1 computer science.pptx
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
L02 Software Design
L02 Software DesignL02 Software Design
L02 Software Design
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Inheritance
InheritanceInheritance
Inheritance
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental Concepts
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
 

Segundo avance

  • 1. TECHNICAL UNIVERSITY OF MANABÍ FACULTY OF COMPUTER SYSTEMS ENGINEER CAREER ENGLISH PROJECT: PROGRAMMING 2 NAME: AYALA CARRILLO JUAN ALBERTO COURSE: 3 SEMESTER C DELIVERY DATE: 21/ 01/2012
  • 2. Technical University of Manabi mission: Being academics, scientists and professionals responsible, humanistic, ethical and caring, committed to the goals of national development, which contribute to solving the country's problems as university teaching with research, able to generate and apply new knowledge, encouraging the promotion and dissemination of knowledge and culture, under the Constitution of the Republic of Ecuador. visio n: Being university, leader and reference of higher education in Ecuador, promoting the creation, development, transmission and dissemination of science, technology and culture, social recognition and regional and global projection. FACULTY OF COMPUTER missio n: Being a unit with high academic prestige, efficiency, transparency and quality in education, organized in their activities, protagonists of regional and national progress. visio n: Being efficient and innovative professionals in the field of computer science, with honesty, fairness and solidarity, provide answers to the needs of society by raising their standard of living. Inheritance in java
  • 3. Introduction Heredity, understood as a feature of object-oriented programming and more specifically the C + +, to define a class by modifying one or more classes and changes usually consist existentes.Estas add new members (variables or functions), to the class being defined, although it can redefine variables or class member functions existentes.La and is part of this process is called base class and the new class that is obtained is called derived class This in turn may be based on a new class derivation process, thus initiating a class hierarchy. It is one of the key weapons of OOP. Allows you to create new classes that inherit characteristics show in previous classes. This greatly facilitates the work that has created standard classes for all programmers and from them create our own personal lessons. This is more convenient than having to create our classes from cero.Para a class to inherit the features of another must use the extends keyword after the class name. A word is followed by the name of the class whose characteristics are inherited. You can have only one class inheritance (a class inherits laque is called superclass and inherited class is called subclass). Example: The idea of inheritance is to allow 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. Every time we find the relation "is-a" between two classes, we are in the presence of inheritance. The existing class is called the superclass or base class, or parent class. The new class is called subclass, derived class, or child class. Through inheritance we can add new fields, and we can add or set methods (override). On mounting a method is redefining the inherited case. The process of inheritance is transitive
  • 4. Types of inheritance 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 + +
  • 5. Advantage • Helps programmers code and saving time, since the parent class has been implemented and verified earlier, deducting only referenced from the derived class to the base class (typically extends, inherits, subclass or other similar keywords, depending on the language). • Objects can be constructed from the like. To do this there needs to be a base class (which can even be part of a broader class hierarchy). • The derived class inherits the behavior and attributes of the base class, and it is common for you to add your own behavior or alter the inherited. • Any class can serve as a base class to create others. Inheritance and information hiding In some languages, the designer can define instance variables and methods of the objects of a class are visible. In C + + and Java this is accomplished with the specifications private, protected and public. Only variables and defined as public methods on an object will be visible for all objects. In other languages like Smalltalk, all instance variables are private and all methods are public. Depending on the language used, the designer can also control which members of the superclass are visible in subclasses. In the case of Java and C + + access specifiers (private, protected, public) of the members of the superclass also affect inheritance: • Private: no private member of the superclass is visible in the subclass. • Protected: protected members of the superclass are visible in the subclass, but not visible to the outside. • Public: public members of the public remain superclass in the subclass. APPLICATION EXAMPLE Consider a simple example of inheritance, for this case we will create a class which is inherit where the surname and assign another class where the name of an "X" person. First let's look at the class to inherit: package inheritance;
  • 6. ClaseHeredada {public class String last; public ClaseHeredada (String Data) { this.Apellido = data;} } Once we have the class that we inherit our class that will contain the name of the "X" and assign the following code: package inheritance; public class extends Inheritance {ClaseHeredada String name; public Inheritance (String text) { super (text); } public void setPersona (String NombrePer) { NombrePer + this.name = this.Apellido; } getPersona public String () { return Name; } } It extends to indicate that we are inheriting class "ClaseHeredada" where the surname. The super is to indicate that we are instantiating the class constructor we are inheriting and methods are getPersona setPersona and with which will capture and take back the name of the person. After this process, we now use in our main instantiating class as follows:
  • 7. public static void main (String [] args) { Inheritance Inheritance X = new ("Arias Figueroa"); X.setPersona ("Kevin Arnold"); System.out.println (X.getPersona ()); } Instantiate Class "Inheritance" passing to its constructor the name of the person which will internally what the upper class "ClaseHeredada", then we assign the name using his method setPersona and print it using getPersona. Made this code should print the person's name by concatenating the name of it. Annexes Drill 1) Basic example of inheritance in Java. In this case the Citizen class inherits from the Person class to take and extend functionality. Human class { protected String name; protected String name; public Human (String name, String name) { this.name = name; this.apellido = name; } public String FullName () { return this.apellido + "," + this.nombre; } identifying public String () { this.nombreCompleto return (); } }
  • 8. Citizen class Human extends { protected String document; public City (String name, String name, String document) { super (name, name); this.documento = document; } identifying public String () { super.identificacion return () + "document" + this.documento; } } Inheritance {public class public static void main (String args []) { Human = new Human ("Emilio", "Rosso"); Citizen b = new City ("Emilio", "Rosso", "3052454545"); Human [] arregloDeHumanos; arregloDeHumanos.push (a); arregloDeHumanos.push (b); identificarPolimorfico (arregloDeHumanos); } public static void identificarPolimorfico (Human [] arregloDeHumanos) { for (int i = 0; i <arregloDeHumanos.length; i + +) {
  • 9. System.out.println ("Identifying" + arregloDeHumanos [i]. Identification ()); } } } But besides this compositional technique is possible to think of cases where a class is an extension of another. That is, a class is like another and also has some sort of characteristic that distinguishes it. For example we might think of the Employee class and define it as: class Employee { String name; int numEmpleado, salary; private static int counter = 0; Employee (String name, int salary) { this.name = name; this.sueldo = salary; numEmpleado = + + count; } public void aumentarSueldo (int percentage) { salary + = (int) (salary * increase / 100); } public String toString () { return "Num employee" + numEmpleado + "Name:" + name + "Salary:" + salary; } }