Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7

Size: px
Start display at page:

Download "Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7"

Transcription

1 Programming Using C# QUEEN S UNIVERSITY BELFAST Practical Week 7

2 Table of Contents PRACTICAL EXERCISE TASK 1: Zoo Park (Without Inheritance)... 2 TASK 2: Zoo Park with Inheritance... 5 TASK 3: Different Animals make different noises... 8 TASK 4: Multiple inheritance Exercise 2: Testing your knowledge TASK 1: WHAT S THE OUTPUT? TASK 2: Overloading EXERCISE 3: Zoo Interface TASK 1: Zoo Keeper TASK 2: Accepting Input QUEEN S UNIVERSITY BELFAST

3 PRACTICAL 7 Practical 6 introduced you to Windows Forms. This allows you to create more exciting programs with a more intuitive user interface than the Console window. This practical builds on the concepts of objects and in particular introduces inheritance. Inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes. EXERCISE 1 The first part of this exercise will set up a Zoo program without the use of inheritance. We will then move on to create it using inheritance and you should see the benefits of being able to control how your objects behave. TASK 1: Zoo Park (Without Inheritance) This task requires you to create a console application which will print the details of several animals in a zoo. Step 1: From the Visual Studio File menu, select New (or press Ctrl+Shift+n), then click on Project. From the New Project window that opens select C#, Console Application and name it e.g. Prac07Ex01Task01. Step 2: Right Click on Program.cs in the Solution Explorer and Rename to ZooPark.cs and select Yes in the followed popup. Step 3: As well as the ZooPark class we need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Right click on the Project in the Solution Explorer, select Add and click Class to add a new class. Name it Animal and click Add. NOTE: The Animal class will be a blue print for the animal objects and will contain the states and behaviours relevant to all animals. We will now add several variables and methods to the Animal class. Step 4: Let s declare the attributes (states) the animal will have e.g. name, age etc. declared in the Animal class, see Figure 1. This is Figure 1 Step 5: Now we will add a constructor to the Animal class that will allow you to create an instance of the Animal class with the required details, see Figure 2. Figure 2 2 QUEEN S UNIVERSITY BELFAST

4 Step 6: We have enough set up to be able to create Animal objects in our ZooPark class. Let s now navigate to the ZooPark.cs class and enter the code as per Figure 3. Figure 3 Step 7: We will know add methods to the Animal class that will allow each animal to carry out several common functions: Sleep(): a method to make the animal lie down and take a nap Eat(): a method to make the animal eat MakeNoise(): a method to allow the animal to make a sound Return to the Animal.cs class and enter the code as per Figure 4. Figure 4 Step 8: Our class now allows the animals to eat, sleep and make a noise. However, what not all animals make the same noise and they don t eat the same food. Therefore we need more methods added, see Figure 5. Figure 5 3 QUEEN S UNIVERSITY BELFAST

5 As you can see the class is becoming quite cluttered and contains methods that will not be used by all animals. For example, wolves will not make an eagle noise or a lion noise but the animal class contains methods to allow this. We will now use inheritance to create a base Animal class which will give the animals everything they have in common e.g. Name, Make a Noise and then create sub classes that inherit from the base class and contain more specific behaviours. This is best described using UML diagrams. Figure 6 provides a UML for the Zoo. Figure 6 4 QUEEN S UNIVERSITY BELFAST

6 TASK 2: Zoo Park with Inheritance We will create the Zoo using inheritance in this part of the practical. This should enable you to see the benefits of being able to control how your objects behave both generically and specifically. Step 1: From the Visual Studio File menu, select New (or press Ctrl+Shift+n), then click on Project. From the New Project window that opens select C#, Console Application and name it e.g. Prac07Ex01Task02. Step 2: Navigate to your Solution folder using Windows Explorer. Open the Task01 folder and copy the Animal.cs and ZooPark.cs files and paste them into the Task 02 folder (again using Windows Explorer). Step 3: In Visual Studio right click on the project in the Solution Explorer window and select Add>Existing Item. This should open the Task 02 folder and you should see the Animal.cs and ZooPark.cs files. Click on Animal.cs and the click the add button. Step 4: Repeat this for the ZooPark.cs file. Finally delete the Program.cs file as this will cause a conflict both this file and ZooPark.cs hold a Main method and C# doesn t know which one to execute. Your Solution Explorer should now reflect the changes, see Figure 7. Delete this file! Figure 7 Step 5: Open the Animal.cs class and change the namespace to reflect the Project name i.e. Task 02. Then repeat this for the ZooPark.cs class. Step 6: Navigate back to the Animal.cs class. Remove all methods except for eat(), sleep() and makenoise() (you should not delete the constructor). Note: The Animal.cs class is the base class which contains all of the generic states and behaviours that each animal will have. However, the zoo contains several different animals including Tigers, Eagles and Wolves. We will now have to create a class for each specific animal but it will be able to inherit generic states and behaviours from the Animal base class. Step 7: Create a Tiger class that inherits from the base Animal class. To do this, add a new class to your project called Tiger.cs which will create a blank class, see Figure 8. Figure 8 5 QUEEN S UNIVERSITY BELFAST

7 NOTE: We mentioned that you should inherit the generic states and behaviours from the base class (i.e. the Animal.cs class). This will mean that we can apply any generic attributes or functions but in the sub class we can then define more specific attributes and functions (refer to the UML in Figure 6). The syntax is as follows: Step 8: Therefore to allow the Tiger to inherit from the Animal class, change the class definition to reflect Figure 9. Figure 9 Step 9: Let s navigate back to the ZooPark.cs class where you will see the three Animal objects created. Comment out the tonytiger Animal object; this has been set up using the base class but we now want it to be of the specific subclass Tiger. Now create an instance of the Tiger class to see if it does in fact inherit from the Animal class, see Figure 10. Figure 10 Note: we currently have no constructor in the Tiger and therefore we do not need to specify values for any attributes. Step 10: If you try to access the public methods and variables of the Animal object and the Tiger object, you can see that Tiger has inherited all of the public methods and attributes, see Figure 11. Figure 11 Step 11: Now let s create the constructor for the Tiger. It will inherit the attributes from the base class and also set a species and a number of stripes. Return to the Tiger.cs class and add a constructor, see Figure QUEEN S UNIVERSITY BELFAST

8 Figure 12 Note: We pass in the values for name, diet, location, weight, age, colour, species and numstripes. The first six are immediately passed to the base class to set up the appropriate generic instance variables. The species and numstripes parameters are then used within the Tiger constructor to set up the specific instance variables relating to the tiger. Step 12: Return to the ZooPark.cs class and amend the creation of the Tiger object, see Figure 13. Figure 13 Step 13: Create classes for a Wolf and an Eagle that all inherit from the base Animal class, as per the details in the UML, see Figure 6. Alter the creation of the two remaining Animal objects so that they are now an Eagle object and a Wolf object, see Figure 14. Figure 14 Note: Now you have subclasses for each animal that all inherit from the base Animal class. We also have specified each subclass of animal, in that they all take the attributes from the base class but the Tiger and Eagle has then more specific states. The idea of inheritance implements the IS-A relationship. For example, Tiger IS-A animal and Wolf IS-A Animal. Step 14: We now need to add some methods which are unique to each animal subclass. We will use the Eagle as an example. Therefore, open the Eagle class and add methods, see Figure 15. Figure 15 Note: If you try to access the public methods and variables of an Eagle object, you can see that Eagle has inherited all of the public methods and attributes of Animal but also has its own specific methods and attributes as shown below. 7 QUEEN S UNIVERSITY BELFAST

9 TASK 3: Different Animals make different noises Tigers roar, wolves howl and eagle s whistle. Each of the classes that inherit from Animal will a have makenoise() method, but each of those methods will work a different way and have different code. When a subclass changes the behaviour of one of the methods that it inherited, we say that it overrides the method. Therefore, when you have a subclass that inherits from a base class, it must inherit all of the base behaviours but you can modify them in the subclass so they are not performed exactly the same way i.e. they become specific. Step 1: Continue working on your project from Task 2 (Exercise 1). To allow the base methods to be overridden, the base methods must be marked as virtual. The virtual keyword designates a method that is overridden in subclasses. Open the Animal.cs class and mark the makenoise() method as virtual as shown below: Figure 16 Step 2: Since the base makenoise() method is now virtual, we can override this method in the Tiger class to allow the Tiger object to ROAARRRR when the makenoise() method is called. To do this, create a makenoise() method in the Tiger class and include the override keyword in the method declaration, see Figure 17. Figure 17 Step 3: Return to the ZooPark.cs class and call the makenoise() method on a Tiger object and an Animal object, see Figure 18. Figure 18 Step 4: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5, see Figure 19. Figure 19 Step 5: Add an override method for makenoise() in the Eagle and Wolf subclasses to perform the correct animal noise e.g. Wolf howls, Eagle whistle. Step 6: We will now override the eat() method in the base class and then for the Tiger subclass to allow the tiger to eat the correct amount of meat. First amend the eat() method as virtual in the base Animal class, see Figure QUEEN S UNIVERSITY BELFAST

10 Figure 20 Step 7: Now create an eat() method in the Tiger class and include the override keyword in the method declaration, see Figure 21. Figure 21 Step 8: Return to the ZooPark.cs and call the eat() method on a Tiger object, Wolf object and an Animal object to view which method is executed, see Figure 22. Figure 22 Step 9: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5, see Figure 23. Figure 23 Note: As we have not yet overridden the eat() method in the Wolf subclass it looks to the parent (or base class). Therefore, when we call the eat() method on the Wolf object it returns An animal eats. Step 10: Override the eat() method in each subclass to allow each animal to eat the correct food and the correct quantity e.g. Wolf eat 10lbs of meat, Eagles eat 1lb of fish. Step 11: Test the eat() method for each of the objects. Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5. Step 12: Time to be creative so decide on a new method that the animal will perform. Add a new method in the Animal class that can be overridden and then override the method in the subclasses of the animals that can perform this action. Step 13: You can also complete the other methods that are part of the subclasses with appropriate information and test them. 9 QUEEN S UNIVERSITY BELFAST

11 TASK 4: Multiple inheritance So the Zoo Park is starting to take shape but could we make it better. At the moment Tiger inherits from the base class Animal but if a Lion joined our Zoo than since they are both Big Cats they will have some common methods and attributes. Why don t we make a Feline class that inherits from Animal and make the Tiger inherit from the Feline class instead of the Animal class which will contain all of the common methods and attributes specific to Cats and also all from the Animal base class. Figure 24 illustrates an update UML. Figure 24 Step 1: Add the new Feline class that inherits from the base Animal class, see Figure 25. Figure QUEEN S UNIVERSITY BELFAST

12 Step 2: We will now need to alter the Tiger class as it needs to inherit from the Feline (rather than Animal) class. Amend the code in Tiger.cs as per Figure 26. Figure 26 Step 3: Add the common Feline attributes and methods to the feline class, as per the UML in Figure 24. Step 4: Return to ZooPark.cs and call a method of the Tiger class, the Feline class and the base Animal class, see Figure 27. Figure 27 Step 5: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5, see Figure 28. Figure 28 Note: The sleep() method is executed in the Feline class for the tiger object but for all other objects the method in the base class is executed. The eat() method is executed in the Tiger class. Step 7: The Zoo has a new arrival and it is a Lion. Now add a new Lion class that inherits from the Feline. Step 6: The Zoo has another new arrival and it is a Penguin. Now add a new Bird class that inherits from the base Animal class as there are now two birds that will share some common attributes and methods e.g. wingspan and bird species. Step 7: You will also need a new Penguin class that inherits from the Bird class you should also change the Eagle class to inherit from the Bird class instead of directly from the Animal class. Think of methods and attributes that only birds would have and methods and attributes that are unique to each type of bird. For example, you could add a Fly method in to the Bird class and in each subclass state if that bird can fly or not by overriding the method. Step 8: Remember to fully test your program using the ZooPark.cs file. 11 QUEEN S UNIVERSITY BELFAST

13 Exercise 2: Testing your knowledge TASK 1: WHAT S THE OUTPUT? You should try to work out the code in Figure 29 on paper and then transfer the code into Visual Studio and run it to see what output you actually get. Remember that if you don t get the answer you expect to check both your workings on paper and the code Figure 29 Part A: What will the following code display given the code in Figure 29? 12 QUEEN S UNIVERSITY BELFAST

14 Part B: What will the following code display given the code in Figure 29? TASK 2: Overloading Overloading is what happens when you have two methods with the same name but different signatures. Step 1: From the Visual Studio File menu, select New (or press Ctrl+Shift+n), then click on Project. From the New Project window that opens select C#, Console Application and name it e.g. Prac07Ex02Task02. Step 2: Add two methods that have the same name but the parameter list in the method header is different, see Figure 30. Figure 30 Note: We now have two methods that can be called by passing in one variable or two and print out the variables to the Console. Step 3: Call each method using different parameters, test your code and view the Console, see Figure 31. Figure 31 At compile time, the compiler works out which one it's going to call, based on the compile time types of the arguments and the target of the method call e.g. if the method call contains a string and an int, call the method that prints both. C# generally does not allow two methods in the same class to have the same name unless the number or type of the parameters differs. 13 QUEEN S UNIVERSITY BELFAST

15 EXERCISE 3: Zoo Interface The exercise will use Windows Forms Applications to demonstrate inheritance and to further enhance the use of GUI s. We will continue to use the Zoo example. TASK 1: Zoo Keeper Step 1: From the Visual Studio File menu, select New (or press Ctrl+Shift+n), then click on Project. From the New Project window that opens select C#, Windows Form Application and name it e.g. Prac07Ex03Task01. Step 2: Right click on Form1.cs in the Solution Explorer and rename to ZooKeeper.cs. Step 3: Using the Properties window, change the title of your form to something meaningful e.g. Zoo Keeper. Step 4: Navigate to your Solution folder using Windows Explorer. Open the Exercise 1 Task 2 folder and copy the Animal.cs, Feline.cs, Bird.cs, Tiger.cs, Wolf.cs, Eagle.cs, Lion.cs and Penguin.cs files and paste them into the Exercise 3 Task 1 folder (again using Windows Explorer). Step 3: In Visual Studio right click on the project in the Solution Explorer window and select Add>Existing Item. This should open the Task 01 folder and you should see all the files you have just copied. Click on them all while holding down the CTRL key on the keyboard and the click the add button. Step 4: Update the namespace reference for these files. Step 5: Create the GUI illustrated in Figure 32 using the toolbox to add elements to the form e.g. Labels, Buttons and text boxes. You can reposition any element on the screen by clicking and dragging the element to the desired location. You should also remember to name each of the elements appropriately Figure 32 Note: To check that the code will work as designed we will test if, when we press one of the buttons the Current Information text box is populated. We will then move on to take user input. 14 QUEEN S UNIVERSITY BELFAST

16 Step 6: As the instance variables are private we will need accessor and mutator methods to access and change information held in these variables. Refer to practical 4 and create these methods for the Animal.cs class. Step 7: Double click on the Eagle Button to create the click event method automatically and add the following code. For this to work at this stage we will need to create an instance of the Eagle, see Figure 33. Figure 33 Step 8: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5, see Figure 34. Figure QUEEN S UNIVERSITY BELFAST

17 TASK 2: Accepting Input Step 1: Continue working on the same project, right click on the Project in the Solution Explorer and select Add -> Windows Form. Name the Form EagleInut and click Add. Create a user interface similar to Figure 35. Remember to name all of the input fields appropriately. Figure 35 Step 2: Navigate to Form1.cs and create a new object reference to the EagleInput form, see Figure 36. Figure 36 Step 3: We will not update the code for the Eagle button (in the Form1.cs) so that when clicked it opens the new EagleInput form, see Figure 37. Figure 37 Step 8: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5. Test the program by clicking on the Eagle button the Eagle Input form should open. We will now implement the Submit Details button to actually create a new Eagle. 16 QUEEN S UNIVERSITY BELFAST

18 Step 9: Navigate to the EagleInput.cs [Design] file and double click on the Submit Details button. When this button is clicked the details will be read from each field in the form and a new Eagle object will be created. The information will then be printed in a pop up window, see Figure 38. Figure 38 Step 8: Save your work (Ctrl+Shift+S), run the program by clicking the start button on the toolbar or use the shortcut Ctrl+F5. Test the program by clicking on the Eagle button the Eagle Input form should open, enter details and click on the Submit button. Step 9: Now add the remaining functionality to this program for the rest of the animals. 17 QUEEN S UNIVERSITY BELFAST

Teacher Training Solutions

Teacher Training Solutions Teacher Training Solutions Practical 7 Exercise 1 Task 1 class Animal private String name; private String diet; private String location; private double weight; private int age; private String colour; Page

More information

Inheritance & Polymorphism

Inheritance & Polymorphism Inheritance & Polymorphism Procedural vs. object oriented Designing for Inheritance Test your Design Inheritance syntax **Practical ** Polymorphism Overloading methods Our First Example There will be shapes

More information

Object-Oriented ProgrammingInheritance & Polymorphism

Object-Oriented ProgrammingInheritance & Polymorphism Inheritance Polymorphism Overriding and Overloading Object-Oriented Programming Inheritance & Polymorphism Inf1 :: 2008/09 Inheritance Polymorphism Overriding and Overloading 1 Inheritance Flat Hierarchy

More information

Object-Oriented Programming More Inheritance

Object-Oriented Programming More Inheritance Object-Oriented Programming More Inheritance Ewan Klein School of Informatics Inf1 :: 2009/10 Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 1 / 45 1 Inheritance Flat Hierarchy

More information

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE

More information

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Chapter 12 OOP: Creating Object-Oriented Programs McGraw-Hill 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter Objectives - 1 Use object-oriented terminology correctly Create a two-tier

More information

Inf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics

Inf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics Inf1-OOP Inheritance and Interfaces Ewan Klein, Perdita Stevens School of Informatics January 12, 2013 Encapsulation Again Inheritance Encapsulation and Inheritance The Object Superclass Flat vs. Nested

More information

Encapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass

Encapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass Encapsulation Again Inheritance Encapsulation and Inheritance Inf1-OOP Inheritance and Interfaces Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 9, 2015 The Object

More information

Inheritance and Polymorphism. CS180 Fall 2007

Inheritance and Polymorphism. CS180 Fall 2007 Inheritance and Polymorphism CS180 Fall 2007 Definitions Inheritance object oriented way to form new classes from pre-existing ones Superclass The parent class If class is final, cannot inherit from this

More information

Inf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics

Inf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics Inf1-OP Inheritance Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 12, 2018 UML Class Diagrams UML: language for specifying and visualizing OOP software

More information

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein.

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. Inf1-OP Inheritance UML Class Diagrams UML: language for specifying and visualizing OOP software systems UML class diagram: specifies class name, instance variables, methods,... Volker Seeker, adapting

More information

Inheritance & Polymorphism. Object-Oriented Programming

Inheritance & Polymorphism. Object-Oriented Programming Inheritance & Polymorphism Object-Oriented Programming Outline Example Design an inheritance structure IS-A and HAS-A Polymorphism protected access level Rules for overriding the Object class Readings:

More information

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012 More OO Fundamentals CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals

More information

Java Session. Day 2. Reference: Head First Java

Java Session. Day 2. Reference: Head First Java Java Session Day 2 shrishty_bcs11@nitc.ac.in Reference: Head First Java Encapsulation This hides the data!! How do we do it? By simply using public private access modifiers. 1. Mark the instance variables

More information

CIS Intro to Programming in C#

CIS Intro to Programming in C# OOP: Creating Classes and Using a Business Tier McGraw-Hill 2010 The McGraw-Hill Companies, Inc. All rights reserved. Understand how a three-tier application separates the user interface from the business

More information

MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011

MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals

More information

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009

Object Fundamentals Part Two. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 Object Fundamentals Part Two Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 3 09/01/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

Inheritance and Polymorphism in Java

Inheritance and Polymorphism in Java Inheritance and Polymorphism in Java Introduction In this article from my free Java 8 course, I will be discussing inheritance in Java. Similar to interfaces, inheritance allows a programmer to handle

More information

Object Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR)

Object Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR) Object Oriented Programming Part II of II Steve Ryder Session 8352 JSR Systems (JSR) sryder@jsrsys.com New Terms in this Section API Access Modifier Package Constructor 2 Polymorphism Three steps of object

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Chapter 12 OOP: Creating Object- Oriented Programs McGraw-Hill Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Objectives (1 of 2) Use object-oriented terminology correctly. Create

More information

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 02 Features of C#, Part 1 Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 Module Overview Constructing Complex Types Object Interfaces and Inheritance Generics Constructing

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

Software Development (cs2500)

Software Development (cs2500) Software Development (cs2500) Lecture 31: Abstract Classes and Methods M.R.C. van Dongen January 12, 2011 Contents 1 Outline 1 2 Abstract Classes 1 3 Abstract Methods 3 4 The Object Class 4 4.1 Overriding

More information

Previously, on Lesson Night... From Intermediate Programming, Part 1

Previously, on Lesson Night... From Intermediate Programming, Part 1 Previously, on Lesson Night... From Intermediate Programming, Part 1 Struct A way to define a new variable type. Structs contains a list of member variables and functions, referenced by their name. public

More information

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment 4 Working with Objects 41 This chapter covers! Overview! Properties and Fields! Initialization! Constructors! Assignment Overview When you look around yourself, in your office; your city; or even the world,

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

CS100J Prelim I, 29 Sept. 2003

CS100J Prelim I, 29 Sept. 2003 CS100J Prelim I, 29 Sept. 2003 CORNELL NETID NAME (PRINT LEGIBLY!) (last, first) Question 0 out of 02 This 90-minute exam has 6 questions worth a total of 100 points. Question 1 out of 20 We suggest that

More information

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A. HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,

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

OVERRIDING. 7/11/2015 Budditha Hettige 82

OVERRIDING. 7/11/2015 Budditha Hettige 82 OVERRIDING 7/11/2015 (budditha@yahoo.com) 82 What is Overriding Is a language feature Allows a subclass or child class to provide a specific implementation of a method that is already provided by one of

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

C18a: Abstract Class and Method

C18a: Abstract Class and Method CISC 3115 TY3 C18a: Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/31/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism Abstract

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance

More information

Subclassing, con.nued Method overriding, virtual methods, abstract classes/methods. COMP 401, Spring 2015 Lecture 9 2/19/2015

Subclassing, con.nued Method overriding, virtual methods, abstract classes/methods. COMP 401, Spring 2015 Lecture 9 2/19/2015 Subclassing, con.nued Method overriding, virtual methods, abstract classes/methods COMP 401, Spring 2015 Lecture 9 2/19/2015 Subclassing So Far A subclass inherits implementa.on details from its superclass

More information

QUESTIONS FOR AVERAGE BLOOMERS

QUESTIONS FOR AVERAGE BLOOMERS MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/

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

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. QUIZ How

More information

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism Programming using C# LECTURE 07 Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism What is Inheritance? A relationship between a more general class, called the base class

More information

Your First Windows Form

Your First Windows Form Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

More information

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011 UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011 1 Goals of the Lecture Review the material in Chapter 2 of the Textbook Cover key parts of the UML notation

More information

Assessment details for All students Assessment item 1

Assessment details for All students Assessment item 1 Assessment details for All students Assessment item 1 Due Date: Weighing: 20% Thursday of Week 6 (19 th April) 11.45 pm AEST 1. Objectives The purpose of this assessment item is to assess your skills attributable

More information

Logistics. Final Exam on Friday at 3pm in CHEM 102

Logistics. Final Exam on Friday at 3pm in CHEM 102 Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create

More information

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points. Java for Non Majors Final Study Guide April 26, 2017 The test consists of 1. Multiple choice questions 2. Given code, find the output 3. Code writing questions 4. Code debugging question 5. Short answer

More information

Object-Oriented Programming

Object-Oriented Programming iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 40 Overview 1 2 3 4 5 2 / 40 Primary OOP features ion: separating an object s specification from its implementation. Encapsulation: grouping related

More information

Instance Members and Static Members

Instance Members and Static Members Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information

Building custom components IAT351

Building custom components IAT351 Building custom components IAT351 Week 1 Lecture 1 9.05.2012 Lyn Bartram lyn@sfu.ca Today Review assignment issues New submission method Object oriented design How to extend Java and how to scope Final

More information

CSCE 145 Exam 2 Review No Answers. This exam totals to 100 points. Follow the instructions. Good luck!

CSCE 145 Exam 2 Review No Answers. This exam totals to 100 points. Follow the instructions. Good luck! CSCE 145 Exam 2 Review No Answers This exam totals to 100 points. Follow the instructions. Good luck! Chapter 5 This chapter was mostly dealt with objects expect questions similar to these. 1. Create accessors

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

1.00 Lecture 14. Exercise: Plants

1.00 Lecture 14. Exercise: Plants 1.00 Lecture 14 Inheritance, part 2 Reading for next time: Big Java: sections 9.1-9.4 Exercise: Plants Create a base class Plant Plant: Private data genus, species, isannual Write the constructor Create

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming (Spring 2012) Lecture #31: Software Reuse through Inheritance Zhong Shao Department of Computer Science Yale University Office: 314 Watson http://flint.cs.yale.edu/cs112

More information

Week 11: Class Design

Week 11: Class Design Week 11: Class Design 1 Most classes are meant to be used more than once This means that you have to think about what will be helpful for future programmers There are a number of trade-offs to consider

More information

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

More About Objects. Zheng-Liang Lu Java Programming 255 / 282 More About Objects Inheritance: passing down states and behaviors from the parents to their children. Interfaces: requiring objects for the demanding methods which are exposed to the outside world. Polymorphism

More information

The first program: Little Crab

The first program: Little Crab Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,

More information

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

Inheritance CSC 123 Fall 2018 Howard Rosenthal

Inheritance CSC 123 Fall 2018 Howard Rosenthal Inheritance CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Defining what inheritance is and how it works Single Inheritance Is-a Relationship Class Hierarchies Syntax of Java Inheritance The super Reference

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

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: has a CSC Employee. Supervisor CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog

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 A1 Posted over the weekend Two ques?ons (s?ll long ques?ons) Review of main concepts from COSC 111 Prac?ce coding

More information

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM This handout explains what you have to know for the first prelim. Terms and their meaning Below, we summarize the terms you should

More information

Introduction to Computation and Problem Solving

Introduction to Computation and Problem Solving Class 13: Inheritance and Interfaces Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward 2 More on Abstract Classes Classes can be very general at the top of

More information

CSC207 Week 3. Larry Zhang

CSC207 Week 3. Larry Zhang CSC207 Week 3 Larry Zhang 1 Announcements Readings will be posted before the lecture Lab 1 marks available in your repo 1 point for creating the correct project. 1 point for creating the correct classes.

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

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

9/17/2018 Programming Data Structures. Encapsulation and Inheritance

9/17/2018 Programming Data Structures. Encapsulation and Inheritance 9/17/2018 Programming Data Structures Encapsulation and Inheritance 1 Encapsulation private instance variables Exercise: 1. Create a new project in your IDE 2. Download: Employee.java, HourlyEmployee.java

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

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn the

More information

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK Mock Exam 2010 Second Year Computer Science CS2500: Software Development Dr Mock

More information

Assignment 1: Meet Dodo

Assignment 1: Meet Dodo Assignment 1: Meet Dodo Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license, https://creativecommons.org/licenses/by/4.0/

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

CS 61B Discussion 4: Inheritance Fall 2018

CS 61B Discussion 4: Inheritance Fall 2018 CS 61B Discussion 4: Inheritance Fall 2018 1 Creating Cats Given the Animal class, fill in the definition of the Cat class so that it makes a "Meow!" noise when greet() is called. Assume this noise is

More information

Promo Buddy 2.0. Internet Marketing Database Software (Manual)

Promo Buddy 2.0. Internet Marketing Database Software (Manual) Promo Buddy 2.0 Internet Marketing Database Software (Manual) PromoBuddy has been developed by: tp:// INTRODUCTION From the computer of Detlev Reimer Dear Internet marketer, More than 6 years have passed

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

CS Programming I: Inheritance

CS Programming I: Inheritance CS 200 - Programming I: Inheritance Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Inheritance

More information

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: has a CSE143 Sp Student. CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches

More information

Adding content to your Blackboard 9.1 class

Adding content to your Blackboard 9.1 class Adding content to your Blackboard 9.1 class There are quite a few options listed when you click the Build Content button in your class, but you ll probably only use a couple of them most of the time. Note

More information

Structured Programming

Structured Programming CS 170 Java Programming 1 Objects and Variables A Little More History, Variables and Assignment, Objects, Classes, and Methods Structured Programming Ideas about how programs should be organized Functionally

More information

HO-1: INTRODUCTION TO FIREWORKS

HO-1: INTRODUCTION TO FIREWORKS HO-1: INTRODUCTION TO FIREWORKS The Fireworks Work Environment Adobe Fireworks CS4 is a hybrid vector and bitmap tool that provides an efficient design environment for rapidly prototyping websites and

More information

WEB APPLICATION ENGINEERING II

WEB APPLICATION ENGINEERING II WEB APPLICATION ENGINEERING II Lecture #9 Umar Ibrahim Enesi Objectives Gain understanding of various constructs used in Object Oriented PHP. Understand the advantages of using OOP style over procedural

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

G52CPP C++ Programming Lecture 10. Dr Jason Atkin

G52CPP C++ Programming Lecture 10. Dr Jason Atkin G52CPP C++ Programming Lecture 10 Dr Jason Atkin 1 Last lecture Constructors Default constructor needs no parameters Default parameters Inline functions Like safe macros in some ways Function definitions

More information

Design Patterns: State, Bridge, Visitor

Design Patterns: State, Bridge, Visitor Design Patterns: State, Bridge, Visitor State We ve been talking about bad uses of case statements in programs. What is one example? Another way in which case statements are sometimes used is to implement

More information

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces

Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces Prof. Hwansoo Han T.A. Minseop Jeong T.A. Wonseok Choi 1 In Previous Lecture We

More information

CIS 190: C/C++ Programming. Lecture 11 Polymorphism

CIS 190: C/C++ Programming. Lecture 11 Polymorphism CIS 190: C/C++ Programming Lecture 11 Polymorphism 1 Outline Review of Inheritance Polymorphism Limitations Virtual Functions Abstract Classes & Function Types Virtual Function Tables Virtual Destructors/Constructors

More information

WORD PROCESSING ASSIGNMENT # 1 ~ FILENAME: FONTS

WORD PROCESSING ASSIGNMENT # 1 ~ FILENAME: FONTS ASSIGNMENT # 1 ~ FILENAME: FONTS 1. Open Word 2. Click on the Office Button Navigate to the folder where your teacher has put the Word Processing U nit Files. Open the file called Fonts. 3. Create a Header

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;

More information

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Objects and References: Outline Variables of a Class Type Defining an equals Method for a Class Boolean-Valued Methods Parameters of a Class Type Variables of a Class

More information

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created. + Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create

More information

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes CS/ENGRD 2110 FALL 2017 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due tomorrow night (17 February) Get started on A3 a method every other day.

More information