INTERFACE WHY INTERFACE

Size: px
Start display at page:

Download "INTERFACE WHY INTERFACE"

Transcription

1 INTERFACE WHY INTERFACE Interfaces allow functionality to be shared between objects that agree to a contract on how the software should interact as a unit without needing knowledge of how the objects accomplish their task. Designing to a Java Interface comes from the slogan: Program to the interface, not the implementation! When you write a class that depends on another, collaborator class, you should rely on the collaborator s interface its specification and not its coding (its implementation). This way you design classes separately yet the assembled collection works A higher level of abstraction allows us to utilize methods and classes with a higher degree of commonality. Structures and approaches can be shared in a wider variety of implementations. You can reuse frameworks of the past and improve on functionality without having to make any changes to already existing work. You simply improve on the next iteration Cleanly separates implementation of behavior from description of the behavior Means the implementation is easily changed Vehicle vehicle = new MotorBike(); // might become Vehicle vehicle = new MotorCar(); Many Object Oriented systems are defined almost entirely of interfaces Describes how the system will function The actual implementation is introduced later A class can only extend one other class, but it can implement multiple interfaces. In effect using interfaces gives us the benefit of multiple inheritance without many of its problems. You can write methods that work for more than one kind of class

2 INTERFACE FEATURES A Java interface is a collection of abstract methods and constants. An abstract method is a method header without a method body. An abstract method can be declared using the modifier abstract, but because all methods in an interface are abstract, usually it is left off. An interface is used to establish a set of methods that a class will implement. An interface cannot be instantiated. Methods in an interface have public visibility by default. A class formally implements an interface by: stating so in the class header. providing implementations for each abstract method in the interface. A class can implement multiple interfaces. A class can implement any number of interfaces. Interfaces are compiled into bytecode just like classes. Can use interface as a data type for variables. Can also use an interface as the result of a cast operation. The interfaces are listed in the implements clause. HOW TO DEFINE AN INTERFACE? interface is a reserved word public interface Doable { void dothis(); int dothat(); void dothis2 (float value, char ch); boolean dotheother (int num); None of the methods in an interface are given a definition (body), because they are by default abstract methods

3 CLASS AND INTERFACE FEATURES The class must implement all methods in all interfaces listed in the header OR declare itself to be abstract. Classes can implement any number of interfaces public class MotorBike implements Vehicle, Motorised Possible to combine extends and implements public class MotorBike extends WheeledVehicle implements Vehicle, Motorised { // Implement all methods of both interfaces EXAMPLE OF INHERITANCE public interface OperateCar { // constant declarations, if any // method signatures int turn(direction direction, double radius, double startspeed, double endspeed); int changelanes(direction direction, double startspeed, double endspeed); int signalturn(direction direction, boolean signalon); int getradarfront(double distancetocar, double speedofcar); int getradarrear(double distancetocar, double speedofcar);... // more method signatures

4 public class BMWCar implements OperateCar { int signalturn(direction,speed){ // proprietary code to signal you are turning // override all the other methods A Toyota manufacturer may have different positioning of the signals on the car, different signal colors, different light intensity, but it is guaranteed that when you use signalturn you will get the same behavior as the BMW car. ANOTHER EXAMPLE There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software interacts. Each group should be able to write their code without any knowledge of how the other group's code is written. Generally speaking, Interfaces are such contracts. Check the following Imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. Automobile manufacturers write software that operates the automobile stop, start, accelerate, turn left, and so forth. Another industrial group, electronic guidance instrument manufacturers, make computer systems that receive GPS (Global Positioning System) position data and wireless transmission of traffic conditions and use that information to drive the car. The auto manufacturers must publish an industry-standard interface that spells out in detail what methods can be invoked to make the car move (any car, from any manufacturer). The guidance manufacturers can then write software that invokes the methods described in the interface to command the car. Neither industrial group needs to know how the other group's software is implemented.

5 In fact, each group considers its software highly proprietary and reserves the right to modify it at any time, as long as it continues to adhere to the published interface. INHERITANCE & INTERFACE Java does not permit multiple inheritance like C++. Some people would say that is a weakness of Java, but there is an alternative view that says Java s interfaces give the advantages of multiple inheritance while avoiding some of the problems. One of the key problems with multiple inheritance is known as the diamond problem. It occurs when a class inherits from two classes with a common ancestor. In this following diagram which represents the diamond problem, when a class inherits from two classes that implement common methods in different ways, what does it inherit? Engine Ignition Gas Engine Ignition: spark plugs Diesel Engine Ignition: glow plugs Multi Fuel Engine Ignition:

6 Java solves the diamond problem by not allowing multiple inheritance from ancestors that have any implementation details. Thus, in Java, classes can only multiply inherit from interfaces and abstract classes that have no implementation details. One interface can inherit another by use of the keyword extends. When a class implements an interface that inherits another interface, it must provide implementations for all methods defined within the interface inheritance chain. Why would we need to have one interface inherit from another instead of modifying the original one? Because all of the implementations we have written in the past would now break. Not all methods would be implemented and we would have to revisit past work. To solve this problem without breaking our previous work, we create a new interface that extends the original one to add new functionality to our design. interface AnyKid { void maycry(); interface MyKid extends AnyKid { void issmart(); How do we use the new features that were added in a new class implementation? class MySon implements MyKid { public void maycry(){ System.out.println( Its ok ); public void issmart() { System.out.println( But he is certainly VERY smart );

7 A class can also implement more than one pertinent interface at the same time but cannot inherit from more than one other class. For a class to inherit from two interfaces, it must provide implementation for all methods declared in each interface. public class StudentEmployee implements Student, Employee { implement all methods from both interfaces here. If there is a conflicting method defined in both interfaces the compiler will let us know INTERFACE VS. ABSTRACT CLASS Interfaces define a contract Contain methods and their signatures Can also include static final constants (and comments) But no implementation Very similar to abstract classes One interface can extend another, but An interface cannot extend a class A class cannot extend an interface Classes implement an interface. An interface cannot have any methods implemented, whereas an abstract class can. A class can implement many interfaces but can only inherit from one superclass. An interface is not part of the class hierarchy. Unrelated classes can implement the same interface. Use an abstract class when you want a roadmap for a collection of subclasses. Subclass when you want to extend a class and add some functionality, whether or not the parent class is abstract.

8 Define an interface when there is no common parent class with the desired functionality, and when you want only certain unrelated classes to have that functionality. Use interfaces as markers to indicate something about a class (e.g. Cloneable be able to make a copy). A common design pattern is to use both an interface and an abstract class depending on the needs of the project. All classes share a single root, the Object class, but there is no single root for interfaces. As a summary. Data Member/ Fields Methods Inheritance Interface Only constants No implementation allowed (no abstract modifier necessary) A subclass can implement many interfaces Abstract class Constants and variable data Abstract or concrete A subclass can inherit only one class Can extend numerous interfaces Cannot extend a class Can implement numerous interfaces Extends one class Root none Object (of all classes) CONSTANTS IN INTERFACE interface OlympicMedal { static final String GOLD = "Gold"; static final String SILVER = "Silver"; static final String BRONZE = "Bronze";

9 public final class OlympicAthlete implements OlympicMedal { public OlympicAthlete(int aid){ //..elided //..elided public void winevent(){ //the athlete gets a gold medal //note the reference is NOT qualified, as //in OlympicMedal.GOLD fmedal = GOLD; // PRIVATE private String fmedal; //possibly null INTERFACES TO USE The Java standard class library contains many helpful interfaces. We will go over three of them: Comparable, Comparator and Cloneable Interface. THE COMPARABLE INTERFACE The Comparable interface contains One abstract method called compareto, which is used to compare two objects. This method compares two objects, in order to impose an order between them. Specifically, it returns one of the following: a negative integer, zero or a positive integer to indicate that the input object is less than, equal or greater than the existing object. Any class can implement Comparable to provide a mechanism for comparing objects of that type if (obj1.compareto(obj2) < 0) System.out.println ("obj1 is less than obj2");

10 The value returned from compareto should be negative is obj1 is less that obj2, 0 if they are equal, and positive if obj1 is greater than obj2 When a programmer designs a class that implements the Comparable interface, it should follow this intent It's up to the programmer to determine what makes one object less than another For example, you may define the compareto method of an Employee class to order employees by name (alphabetically) or by employee number The implementation of the method can be as straightforward or as complex as needed for the situation. Here is an Example: public class Person implements Comparable <Person> { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; public int getage() { return this.age; public String getname() { return this.name; public String tostring() { return ""; public int compareto(person per) { int result=-1; if(this.name.equals (per.getname())==true) result =0; else{ if (this.age > per.getage) { result =1; return result

11 // Testing the compareto method public static void main(string[] args) { Person e1 = new Person("Adam", 45); Person e2 = new Person("Steve", 60); int retval = e1.compareto(e2); switch(retval) { case 0: System.out.println(e1.getName()+" has the same name as + e2.getname() ); break; case -1: { System.out.println("The " + e2.getname() + " is older!"); break; case 1: { System.out.println("The " + e1.getname() + " is older!"); break; Output Steve is older!

12 2. COMPARATOR INTERFACE Comparator interface, which contains two methods, called compare and equals. The compare method compares its two input arguments and imposes an order between them. It returns a negative integer, zero, or a positive integer to indicate that the first argument is less than, equal to, or greater than the second. There should be two classes. The equals method requires an Object as a parameter and aims to decide whether the input object is equal to the comparator. The method returns true, only if the specified object is also a comparator and it imposes the same ordering as the comparator. Here is an Example: public class Company { private int num_of_employess; private String name; public Company(String name, int num_of_employess) { this.name = name; this.num_of_employess = num_of_employess; public int getnumofemployess() { return this.num_of_employess; public String getname() { return this.name;

13 import java.util.comparator; public class SortCompanies implements Comparator <Company> { public int compare (Company comp1, Company comp2) { if(comp1.getnumofemployess()== comp2.getnumofemployess()) return 0; else return comp1.getnumofemployess() > comp2.getnumofemployess()? 1 : -1; public static void main(string[] args) { Company comp1 = new Company("Company1", 20); Company comp2 = new Company("Company2", 15); SortCompanies sortcmp = new SortCompanies(); int retval = sortcmp.compare(comp1, comp2); switch(retval) { case -1: { System.out.println("The " + comp2.getname() + " is bigger!"); break; case 1: { System.out.println("The " + comp1.getname() + " is bigger!"); break; default: System.out.println("The two companies are of the same size!");

14 3. CLONEABLE INTERFACE Cloneable interface which contains the following: The clone method which takes no parameters and it returns back an object of the class Object. The method is used to create a copy of the current object. The method gives back an object of the class Object. The method throws CloneNotSupportedException Here is an Example: public class Employee implements Cloneable { private String firstname; private String lastname; private double salary; Employee() { setfirstname(""); setlastname(""); setsalary(0); Employee(String fname, String lname, double newsalary) { setfirstname(fname); setlastname(lname); setsalary(newsalary); public String tostring() { return "Employee [firstname=" + getfirstname() + ", lastname=" + getlastname() + ", salary=" + getsalary() + "]"; public String getfirstname() { return firstname; public void setfirstname(string firstname) { this.firstname = firstname;

15 public String getlastname() { return lastname; public void setlastname(string lastname) { this.lastname = lastname; public double getsalary() { return salary; public void setsalary(double newsalary) { salary = newsalary; public Object clone() throws CloneNotSupportedException{ return super.clone(); public class TestEmployees { public static void main(string[] args) { Employee e1 = new Employee ("Tom", "Adam", 5000); try { Employee e3 = (Employee) e1.clone(); e3.setfirstname("william"); System.out.println(e1); System.out.println(e3); catch (CloneNotSupportedException c) { System.out.println( An error )

16 DIFFERENCES BETWEEN VARIABLES OF PRIMITIVE TYPES AND REFERENCE TYPES Every variable represents a memory location that holds a value. When you declare a variable, you are telling the compiler what type of value the variable can hold. For a variable of a primitive type, the value is of the primitive type. For a variable of a reference type, the value is a reference to where an object is located. The default value of a data field is null for a reference type, The default value of a variable of primitive data type is 0 for a numeric type, false for a boolean type, and \u0000 for a char type CREATING A COPY OF AN OBJECT When you try to try to copy an object to another object, then dont use = between these two objects. For example: Person P1; Person P2; P2 = P1;

17 This is wrong approach to copy the content of P1 into P2. Instead, you are letting both objects references pointing to the same location. Which means if P2 change something, P1 will be affected. To create a copy of an object, use of the following ways. 1. MANUALLY USING MUTATORS AND ACCESSORS. Create the first object, then declare the second one and after that copy data from object1 into object2 through using mutators method for object2 and accessors methods for object1. 2. USING A COPY CONSTRUCTOR. 3. USE.CLONE() METHOD Check the following Example: public class Employee implements Cloneable { private String firstname; private String lastname; private double salary; Employee() { setfirstname(""); setlastname(""); setsalary(0); Employee(String fname, String lname, double newsalary) { setfirstname(fname); setlastname(lname); setsalary(newsalary); // Copy constructor Employee (Employee newemployee) { setfirstname(newemployee.getfirstname()); setlastname(newemployee.getlastname()); setsalary(newemployee.getsalary());

18 public String tostring() { return "Employee [firstname=" + getfirstname() + ", lastname=" + getlastname() + ", salary=" + getsalary() + "]"; public String getfirstname() { return firstname; public void setfirstname(string firstname) { this.firstname = firstname; public String getlastname() { return lastname; public void setlastname(string lastname) { this.lastname = lastname; public double getsalary() { return salary; public void setsalary(double newsalary) { salary = newsalary; public Object clone() throws CloneNotSupportedException{ return super.clone(); public class TestEmployees { public static void main(string[] args) { Employee e1 = new Employee ("Tom", "Adam", 5000); Employee e2 = new Employee ("Tom", "Adam", 5000); /* You can t copy e1 to e3 using = as follows // e3 and e1 share the same object Employee e3 = e1;

19 e3.setfirstname("rayan"); System.out.println(e1); */ /* // you can use copy constructor as follow // e3 is an independent copy of e1 Employee e3 = new Employee (e1); e3.setfirstname("rayan"); System.out.println(e1); */ /* // Or you can use.clone try{ Employee e3 = (Employee) e1.clone(); e3.setfirstname("rayan"); System.out.println(e1); System.out.println(e3); catch(clonenotsupportedexception c){ /*

20 COMPARE BETWEEN TWO OBJECTS When you compare between two Objects don t use ==. If you are using == then you are comparing the 2 references not their contents. Instead, use the following. The class object (the root of all the classes) has a special method called.equals which you can use to compare two objects based on their content. You have to override this method in the class of the objects that you are trying to compare between. The method.equals defines a method parameter of type Object and its return type is boolean. public boolean equals(object anobject) {... Check the following Example: public class Employee implements Cloneable { private String firstname; private String lastname; private double salary; Employee() { setfirstname(""); setlastname(""); setsalary(0); Employee(String fname, String lname, double newsalary) { setfirstname(fname); setlastname(lname); setsalary(newsalary); Employee (Employee newemployee) { setfirstname(newemployee.getfirstname()); setlastname(newemployee.getlastname()); setsalary(newemployee.getsalary());

21 public String tostring() { return "Employee [firstname=" + getfirstname() + ", lastname=" + getlastname() + ", salary=" + getsalary() + "]"; public String getfirstname() { return firstname; public void setfirstname(string firstname) { this.firstname = firstname; public String getlastname() { return lastname; public void setlastname(string lastname) { this.lastname = lastname; public double getsalary() { return salary; public void setsalary(double newsalary) { salary = newsalary; public boolean equals (Object other){ boolean result; if((other == null) (getclass()!= other.getclass())){ result = false; // end if else{ Employee otheremployee = (Employee)other; result = firstname.equals(otheremployee.getfirstname()) && lastname.equals(otheremployee.getlastname()) && salary == otheremployee.getsalary(); // end else return result; // end equals

22 public class TestEmployees { public static void main(string[] args) { Employee e1 = new Employee ("Tom", "Adam", 5000); Employee e2 = new Employee ("Tom", "Adam", 5000); // You cant use the following to compare between the contents of e1 and e2 if (e1==e2) { System.out.println("e1 and e2 have the same address"); else{ System.out.println("e1 has different address than e2"); // You have to use.equals methods to compare between the content of e1 // and e2 if (e1.equals(e2)) { System.out.println("e1 has the same data members values as e2"); else{ System.out.println("e1 has different data members values than e2");

23 REFERENCES

Defining an interface is similar to creating a new class: // constant declarations, if any

Defining an interface is similar to creating a new class: // constant declarations, if any Interfaces There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a "contract" that spells out how their software interacts. Each

More information

(SE Tutorials: Learning the Java Language Trail : Interfaces & Inheritance Lesson )

(SE Tutorials: Learning the Java Language Trail : Interfaces & Inheritance Lesson ) (SE Tutorials: Learning the Java Language Trail : Interfaces & Inheritance Lesson ) Dongwon Jeong djeong@kunsan.ac.kr; http://ist.kunsan.ac.kr/ Information Sciences and Technology Laboratory, Dept. of

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 21 Interfaces and Abstract Classes Overview Problem: Can we make inheritance flexible? Abstract methods Define methods that will be filled in by children

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Abstract Classes and Interfaces

Abstract Classes and Interfaces Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

SSE3052: Embedded Systems Practice

SSE3052: Embedded Systems Practice SSE3052: Embedded Systems Practice Minwoo Ahn minwoo.ahn@csl.skku.edu Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3052: Embedded Systems Practice, Spring 2018, Jinkyu Jeong

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #23: OO Design, cont d. Janak J Parekh janak@cs.columbia.edu Administrivia HW#5 due Tuesday And if you re cheating on (or letting others see your) HW#5

More information

Interfaces. Quick Review of Last Lecture. November 6, Objects instances of classes. Static Class Members. Static Class Members

Interfaces. Quick Review of Last Lecture. November 6, Objects instances of classes. Static Class Members. Static Class Members November 6, 2006 Quick Review of Last Lecture ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Objects instances of a class with a static variable size

More information

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000 The Object Class Mark Allen Weiss Copyright 2000 1/4/02 1 java.lang.object All classes either extend Object directly or indirectly. Makes it easier to write generic algorithms and data structures Makes

More information

Basic Object-Oriented Concepts. 5-Oct-17

Basic Object-Oriented Concepts. 5-Oct-17 Basic Object-Oriented Concepts 5-Oct-17 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions, which could manipulate any data An object contains

More information

Introduction to Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

Computer Science 210: Data Structures

Computer Science 210: Data Structures Computer Science 210: Data Structures Summary Today writing a Java program guidelines on clear code object-oriented design inheritance polymorphism this exceptions interfaces READING: GT chapter 2 Object-Oriented

More information

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Inheritance models IS- A rela?onship Different from impor?ng classes Inherited classes can be organized

More information

WEEK 13 EXAMPLES: POLYMORPHISM

WEEK 13 EXAMPLES: POLYMORPHISM WEEK 13 EXAMPLES: POLYMORPHISM CASE STUDY: PAYROLL SYSTEM USING POLYMORPHISM Use the principles of inheritance, abstract class, abstract method, and polymorphism to design a payroll project for a car lot.

More information

Chapter 13 Abstract Classes and Interfaces

Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces 1 Abstract Classes Abstraction is to extract common behaviors/properties into a higher level in the class hierarch so that they are shared (implemented) by subclasses

More information

Answer ALL Questions. Each Question carries ONE Mark.

Answer ALL Questions. Each Question carries ONE Mark. SECTION A (10 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (5 Marks) i. Which of the following is not a valid primitive type : a. char b. double c. int

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

Fundamental Java Methods

Fundamental Java Methods Object-oriented Programming Fundamental Java Methods Fundamental Java Methods These methods are frequently needed in Java classes. You can find a discussion of each one in Java textbooks, such as Big Java.

More information

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference CSI1102: Introduction to Software Design Chapter 5: Enhancing Classes Learning objectives: Enhancing Classes Understand what the following entails Different object references and aliases Passing objects

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

COE318 Lecture Notes Week 8 (Oct 24, 2011)

COE318 Lecture Notes Week 8 (Oct 24, 2011) COE318 Software Systems Lecture Notes: Week 8 1 of 17 COE318 Lecture Notes Week 8 (Oct 24, 2011) Topics == vs..equals(...): A first look Casting Inheritance, interfaces, etc Introduction to Juni (unit

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management

More information

Motivations. Objectives. object cannot be created from abstract class. abstract method in abstract class

Motivations. Objectives. object cannot be created from abstract class. abstract method in abstract class Motivations Chapter 13 Abstract Classes and Interfaces You have learned how to write simple programs to create and display GUI components. Can you write the code to respond to user actions, such as clicking

More information

Lecture 4: Extending Classes. Concept

Lecture 4: Extending Classes. Concept Lecture 4: Extending Classes Concept Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you can reuse the existing class s methods and fields, and

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

Banaras Hindu University

Banaras Hindu University Banaras Hindu University A Course on Software Reuse by Design Patterns and Frameworks by Dr. Manjari Gupta Department of Computer Science Banaras Hindu University Lecture 5 Basic Design Patterns Basic

More information

Chapter 13 Abstract Classes and Interfaces. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited

Chapter 13 Abstract Classes and Interfaces. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited Chapter 13 Abstract Classes and Interfaces Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations You have learned how to write simple programs

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

Cloning Enums. Cloning and Enums BIU OOP

Cloning Enums. Cloning and Enums BIU OOP Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

CSI Introduction to Software Design. Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) x 6277

CSI Introduction to Software Design. Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) x 6277 CSI 1102 Introduction to Software Design Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) 562-5800 x 6277 elsaddik @ site.uottawa.ca abed @ mcrlab.uottawa.ca http://www.site.uottawa.ca/~elsaddik/

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces CS 112 Programming 2 Lecture 10 Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces 2 1 Motivations We have learned how to write simple programs to create and display GUI components.

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Create a Java project named week9

Create a Java project named week9 Objectives of today s lab: Through this lab, students will explore a hierarchical model for object-oriented design and examine the capabilities of the Java language provides for inheritance and polymorphism.

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel)

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel) Programmieren II Polymorphism Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) June 4, 2014 1 / 50 Outline 1 Recap - Collections 2 Advanced OOP: Polymorphism Polymorphism

More information

CMSC 132: Object-Oriented Programming II. Interface

CMSC 132: Object-Oriented Programming II. Interface CMSC 132: Object-Oriented Programming II Interface 1 Java Interfaces An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. Interfaces are Java's

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming

More information

Object Oriented Programming. What is this Object? Using the Object s Slots

Object Oriented Programming. What is this Object? Using the Object s Slots 1 Object Oriented Programming Chapter 2 introduces Object Oriented Programming. OOP is a relatively new approach to programming which supports the creation of new data types and operations to manipulate

More information

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass? 1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type

More information

Chapter 13 Abstract Classes and Interfaces

Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces rights reserved. 1 Motivations You have learned how to write simple programs to create and display GUI components. Can you write the code to respond to user actions,

More information

CLASS DESIGN. Objectives MODULE 4

CLASS DESIGN. Objectives MODULE 4 MODULE 4 CLASS DESIGN Objectives > After completing this lesson, you should be able to do the following: Use access levels: private, protected, default, and public. Override methods Overload constructors

More information

Programming Language Concepts: Lecture 2

Programming Language Concepts: Lecture 2 Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 2, 19 January 2009 Classes and

More information

HIBERNATE - SORTEDSET MAPPINGS

HIBERNATE - SORTEDSET MAPPINGS HIBERNATE - SORTEDSET MAPPINGS http://www.tutorialspoint.com/hibernate/hibernate_sortedset_mapping.htm Copyright tutorialspoint.com A SortedSet is a java collection that does not contain any duplicate

More information

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence. Constructor in Java 1. What are CONSTRUCTORs? Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs

More information

Object-Oriented Programming (Java)

Object-Oriented Programming (Java) Object-Oriented Programming (Java) Topics Covered Today 2.1 Implementing Classes 2.1.1 Defining Classes 2.1.2 Inheritance 2.1.3 Method equals and Method tostring 2 Define Classes class classname extends

More information

Interfaces. James Brucker

Interfaces. James Brucker Interfaces James Brucker What is an Interface? An interface is a specification of (1) a required behavior any class that claims to "implement" the interface must perform the behavior (2) constant data

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Informatik II (D-ITET) Tutorial 6

Informatik II (D-ITET) Tutorial 6 Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,

More information

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5, Informatik II Tutorial 6 Mihai Bâce mihai.bace@inf.ethz.ch 05.04.2017 Mihai Bâce April 5, 2017 1 Overview Debriefing Exercise 5 Briefing Exercise 6 Mihai Bâce April 5, 2017 2 U05 Some Hints Variables &

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

More information

Java Classes, Inheritance, and Interfaces

Java Classes, Inheritance, and Interfaces Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

EXERCISES SOFTWARE DEVELOPMENT I. 09 Objects: Inheritance, Polymorphism and Dynamic Binding 2018W

EXERCISES SOFTWARE DEVELOPMENT I. 09 Objects: Inheritance, Polymorphism and Dynamic Binding 2018W EXERCISES SOFTWARE DEVELOPMENT I 09 Objects: Inheritance, Polymorphism and Dynamic Binding 2018W Inheritance I INHERITANCE :: MOTIVATION Real world objects often exist in various, similar variants Attributes

More information

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction

More information

Lab05: Inheritance and polymorphism

Lab05: Inheritance and polymorphism Lab05: Inheritance and polymorphism Inheritance Inheritance creates a new class definition by building upon an existing definition (you extend the original class) The new class can, in turn, can serve

More information

CIS 110: Introduction to computer programming

CIS 110: Introduction to computer programming CIS 110: Introduction to computer programming Lecture 25 Inheritance and polymorphism ( 9) 12/3/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Inheritance Polymorphism Interfaces 12/3/2011

More information

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) 11/28/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Object-oriented programming. What is

More information

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth Outline CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) Object-oriented programming. What is an object? Classes as blueprints for objects. Encapsulation

More information

Classes and Inheritance Extending Classes, Chapter 5.2

Classes and Inheritance Extending Classes, Chapter 5.2 Classes and Inheritance Extending Classes, Chapter 5.2 Dr. Yvon Feaster Inheritance Inheritance defines a relationship among classes. Key words often associated with inheritance are extend and implements.

More information

Object Oriented Programming. I. Object Based Programming II. Object Oriented Programming

Object Oriented Programming. I. Object Based Programming II. Object Oriented Programming Systems programming Object Oriented Programming I. Object Based Programming II. Object Oriented Programming Telematics Engineering M. Carmen Fernández Panadero mcfp@it.uc3m.es 2010 1

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 17 Inheritance Overview Problem: Can we create bigger classes from smaller ones without having to repeat information? Subclasses: a class inherits

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Inheritance Motivation

Inheritance Motivation Inheritance Inheritance Motivation Inheritance in Java is achieved through extending classes Inheritance enables: Code re-use Grouping similar code Flexibility to customize Inheritance Concepts Many real-life

More information

The Object clone() Method

The Object clone() Method The Object clone() Method Introduction In this article from my free Java 8 course, I will be discussing the Java Object clone() method. The clone() method is defined in class Object which is the superclass

More information

Chapter 3 Classes & Objects

Chapter 3 Classes & Objects 1 Chapter 3 Classes & Objects Question 1: Given the code below, 1. public class Try 3. private static int sum = 20; 4. public static void main(string args[]) 5. { 6. Try t1 = new Try(); 7. Try.sum++; 8.

More information

MIDTERM REVIEW. midterminformation.htm

MIDTERM REVIEW.   midterminformation.htm MIDTERM REVIEW http://pages.cpsc.ucalgary.ca/~tamj/233/exams/ midterminformation.htm 1 REMINDER Midterm Time: 7:00pm - 8:15pm on Friday, Mar 1, 2013 Location: ST 148 Cover everything up to the last lecture

More information

Motivations. Chapter 13 Abstract Classes and Interfaces

Motivations. Chapter 13 Abstract Classes and Interfaces Chapter 13 Abstract Classes and Interfaces CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations You have learned how to write simple

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

F I N A L E X A M I N A T I O N

F I N A L E X A M I N A T I O N Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student

More information

Object-Oriented Programming in Java. Topic : Objects and Classes (cont) Object Oriented Design

Object-Oriented Programming in Java. Topic : Objects and Classes (cont) Object Oriented Design Electrical and Computer Engineering Object-Oriented in Java Topic : Objects and Classes (cont) Object Oriented Maj Joel Young Joel.Young@afit.edu 11-Sep-03 Maj Joel Young Using Class Instances Accessing

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

Chapter 5: Enhancing Classes

Chapter 5: Enhancing Classes Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions for AP* Computer Science 3rd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by

More information

Ch 7 Designing Java Classes & Class structure. Methods: constructors, getters, setters, other e.g. getfirstname(), setfirstname(), equals()

Ch 7 Designing Java Classes & Class structure. Methods: constructors, getters, setters, other e.g. getfirstname(), setfirstname(), equals() Ch 7 Designing Java Classes & Class structure Classes comprise fields and methods Fields: Things that describe the class or describe instances (i.e. objects) e.g. last student number assigned, first name,

More information

CS1150 Principles of Computer Science Objects and Classes

CS1150 Principles of Computer Science Objects and Classes CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8

More information

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 09 Inheritance What is Inheritance? In the real world: We have general terms for objects in the real

More information

References. Chapter 5: Enhancing Classes. Enhancing Classes. The null Reference. Java Software Solutions for AP* Computer Science A 2nd Edition

References. Chapter 5: Enhancing Classes. Enhancing Classes. The null Reference. Java Software Solutions for AP* Computer Science A 2nd Edition Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course : Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order

More information

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COMP 250 Winter 2011 Reading: Java background January 5, 2011 Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP

More information

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun Announcements Project 1 spec and code is available on the course website. Due July 15 th. Start early! Midterm I is next Wed in

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) COE318 Lecture Notes: Week 9 1 of 14 COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) Topics The final keyword Inheritance and Polymorphism The final keyword Zoo: Version 1 This simple version models

More information