Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Size: px
Start display at page:

Download "Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1"

Transcription

1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one question: 40 marks) Notes are not permitted in this examination. Do not turn over until you are told to do so by the Invigilator. CMP-4008Y Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

2 Page 2 1. (a) In the context of Java: SECTION A (i) explain the differences between primitive data types and reference types; (ii) distinguish between local variables and instance variables. (b) Explain what is meant by a static method in Java. A static method called numberofitems is to have two parameters, the first corresponding to the cost of one item of a product and the second to the amount of money a customer has available for purchasing items of this product. The method is to return the number of items that may be purchased for the given amount. (i) Write Java code for the method numberofitems. [5 marks] (ii) Give a Java code fragment that uses your method to determine the number of items that may be purchased for 70 given that the cost per item is 13.45, and prints out this value. 2. (a) In the context of Java methods, distinguish between formal parameters and actual parameters. Describe what happens when a method is invoked in Java. [6 marks] (b) Let BankAccount be a Java class. Give a Java statement to create an array called currentaccounts to hold n BankAccount objects. Assume n has been assigned a positive integer value. (c) Suppose that the BankAccount class contains a method with the header public boolean isoverdrawn() which returns true if this BankAccount is overdrawn and false otherwise. Write Java code for a static method that has a

3 Page 3 single formal parameter called accountsarray of type BankAccount [] and returns the number of overdrawn accounts in accountsarray. [7 marks] (d) Explain, in terms of the formal and actual parameters, what then happens when the following code is executed: int odrawnaccounts = numberofoverdrawnaccounts(currentaccounts); 3. (a) In the context of Java, what does inheritance mean? (b) Given the following class public class Building{ protected int numrooms; protected int numfloors; } write a class House that inherits from Building, has an extra field for the number of bedrooms and a method that sets the number of bedrooms. (c) Describe the relationship between Building and House in a UML class diagram. (d) Suppose a class called Street contains a public collection of objects of type House called houses, a further private String field called name and a constructor that takes the number of houses and the street name as arguments. Represent this relationship as a UML class diagram, then implement the class Street. [8 marks] TURN OVER

4 Page 4 4. (a) Give the structure of a class defining a new type of object. [5 marks] (b) For each member of a sports club the following data is held: name (e.g. "Mark Smith"); contact details; year of birth (e.g. 1985); year of joining the club (e.g. 2008); type of membership (either F for family or P for personal). Let Member be a Java class with fields for each of the above data items. In addition, the class Member includes a class variable to keep track of the total number of members, and two class constants, one for the family subscription rate (150 pounds) and the other for the personal subscription rate (100 pounds). (i) Write a skeleton declaration for the class Member, to include definitions for the above fields, class variable and class constants, but no constructors or other method definitions. Assume that a class called ContactDetails has already been written and is available. [6 marks] (ii) Write a constructor for the Member class, with explicit arguments to define the initial values of the instance variables corresponding to the five fields specified above. [You are not required to include any data error-checking.] (iii) Assume that the class ContactDetails contains a method specified as follows: /** * A method to change the address in this ContactDetails newaddress the address to which the address in * this ContactDetails is to be changed. */ public void setaddress(string newaddress)

5 Page 5 Write a mutator method for the class Member to update the address of a member, given a String representing the member s new address. (iv) Write an accessor method to determine the subscription due for a member. TURN OVER

6 Page 6 SECTION B 5. (a) Define what is meant by an algorithm. [5 marks] (b) Give an informal description of the linear search algorithm for searching for a given item in an unsorted array of elements. [5 marks] (c) Give Java code for a static method implementing linear search for a given Comparable object in an array of Comparable objects. Your method should have the following header. public static int linearsearch(comparable [] a, Comparable searchitem) If searchitem is found in array, a, the method is to return the index in a where searchitem is found, otherwise it is to return -1. (d) Distinguish between an array and an ArrayList in Java. [10 marks] (e) Suppose that a class CustomerDetails is used to represent a customer s record. Given that this class is to implement the Comparable interface, give the header for the CustomerDetails class. [2 marks] (f) Now suppose that we wish to store a collection of CustomerDetails objects. Give Java statements to (i) create an ArrayList called customerlist. (ii) create an array called customerarray; [5 marks] (g) Give a Java statement to assign the first CustomerDetails record in customerlist to a CustomerDetails variable, firstcustomer. [2 marks] (h) Give an assignment statement assigning the last CustomerDetails record in customerarray to a CustomerDetails variable, lastcustomer.

7 Page 7 (i) Now let givencustomer be a CustomerDetails variable representing a particular customer s record. Using the method linearsearch specified above, write a Java code fragment to determine whether or not the record for this customer is stored in customerarray. 6. (a) Assume that we have the following classes: Employee, Management, Secretarial, Manual, Accountant, Personal_Assistant and GeneralOffice_Worker. Management, Secretarial and Manual are each subclasses of Employee. Accountant is a subclass of Management, and Personal_Assistant and GeneralOffice_Worker are subclasses of Secretarial. (i) Draw the inheritance hierarchy for this group of classes. [6 marks] (ii) State which of the following assignments are legal, justifying your answers. [9 marks] Employee e1 = new Secretarial(); Employee e2 = new Accountant(); Manual m1 = new Employee(); Secretarial s1 = new Personal_Assistant(); e1 = s1; TURN OVER

8 Page 8 (b) An abstract class, Employee, is defined as follows. public abstract class Employee{ protected String name; protected String nationalinsuranceno; public Employee(String empname, String empninumber){ name = empname; nationalinsuranceno = empninumber; } /** this Employee s monthly pay */ public abstract double getmonthlypay(); public String tostring(){ String resultstring = "Name: " + name + "\n"; resultstring += "NI number: " + nationalinsuranceno; return resultstring; } } (i) Give Java code for a class Management that inherits from Employee and has an additional field (of type double) for annual salary. Make use of super in both the constructor and the tostring method for Management. Your solution should include an implementation of the getmonthlypay() method to override the abstract method in the Employee class. [10 marks] (ii) Define a second derived class of Employee called HourlyWorker which has two additional fields, one for a

9 Page 9 worker s hourly rate of pay (a double) and another for the number of hours that a worker works per month (an int). As above, your solution should make use of super in both the constructor and the tostring method and should include an implementation of the getmonthlypay() method to override the abstract method in the Employee class. [10 marks] (iii) Suppose that employeerecords is an array whose elements are of type Employee. Consider the following Java code fragment : for (Employee e : employeerecords) System.out.println(c.getMonthlyPay()); Explain how execution of this code would result in polymorphic behaviour. [5 marks] END OF PAPER

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 PROGRAMMING FOR NON-SPECIALISTS CMP-5020B Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one

More information

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2012-13 PROGRAMMING 1 CMPC1M0Y Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one

More information

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2013-14 PROGRAMMING FOR NON-SPECIALISTS CMPC2X02 Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section

More information

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015-16 PROGRAMMING FOR APPLICATIONS CMP-4009B Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods

More information

Answer BOTH questions from Section A and ONE question from Section B.

Answer BOTH questions from Section A and ONE question from Section B. UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2013/14 INTRODUCTORY PROGRAMMING CMP-0005B Time allowed: 2 hours Answer BOTH questions from Section A and ONE question

More information

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015-16 DATA STRUCTURES AND ALGORITHMS CMP-5014Y Time allowed: 3 hours Section A (Attempt any 4 questions: 60 marks) Section

More information

Chapter 7. Inheritance

Chapter 7. Inheritance Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and

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

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 INTRODUCTORY PROGRAMMING CMP-0005B Time allowed: 2 hours. Answer BOTH questions from section A and ONE question

More information

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 PROGRAMMING 2 CMP-5015Y Time allowed: 2 hours Answer four questions. All questions carry equal weight. Notes are

More information

EXAMINATION FOR THE BSC (HONS) INFORMATION TECHNOLOGY; BSC (HONS) INFORMATION SYSTEMS & BSC (HONS) COMPUTER SCIENCE; YEAR 1

EXAMINATION FOR THE BSC (HONS) INFORMATION TECHNOLOGY; BSC (HONS) INFORMATION SYSTEMS & BSC (HONS) COMPUTER SCIENCE; YEAR 1 FACULTY OF SCIENCE AND TECHNOLOGY EXAMINATION FOR THE BSC (HONS) INFORMATION TECHNOLOGY; BSC (HONS) INFORMATION SYSTEMS & BSC (HONS) COMPUTER SCIENCE; YEAR 1 ACADEMIC SESSION 2014; SEMESTER 2 PRG1203:

More information

Chapter 2a Class Relationships

Chapter 2a Class Relationships Data Structures for Java William H. Ford William R. Topp Chapter 2a Class Relationships Bret Ford 2005, Prentice Hall Wrapper Classes Convert a value of primitive type to an object. Supply methods to access

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

Exam Duration: 2hrs and 30min Software Design

Exam Duration: 2hrs and 30min Software Design Exam Duration: 2hrs and 30min. 433-254 Software Design Section A Multiple Choice (This sample paper has less questions than the exam paper The exam paper will have 25 Multiple Choice questions.) 1. Which

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

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer

More information

Do not turn over until you are told to do so by the Invigilator.

Do not turn over until you are told to do so by the Invigilator. UNIVERSITY OF EAST ANGLIA School of Mathematics UG End of Year Examination 2002-2003 PROGRAMMING FOR MATHEMATICIANS Time allowed: TWO hours Answer ALL FOUR questions in Section A Answer ONE Question from

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

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

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

Polymorphism. return a.doublevalue() + b.doublevalue();

Polymorphism. return a.doublevalue() + b.doublevalue(); Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces

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

Java Programming Lecture 7

Java Programming Lecture 7 Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used

More information

Chapter 15: Object Oriented Programming

Chapter 15: Object Oriented Programming Chapter 15: Object Oriented Programming Think Java: How to Think Like a Computer Scientist 5.1.2 by Allen B. Downey How do Software Developers use OOP? Defining classes to create objects UML diagrams to

More information

Comp 249 Programming Methodology

Comp 249 Programming Methodology Comp 249 Programming Methodology Chapter 7 - Inheritance Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been extracted,

More information

Intro to Computer Science 2. Inheritance

Intro to Computer Science 2. Inheritance Intro to Computer Science 2 Inheritance Admin Questions? Quizzes Midterm Exam Announcement Inheritance Inheritance Specializing a class Inheritance Just as In science we have inheritance and specialization

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

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

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

CS 302: Introduction to Programming in Java. Lecture 15

CS 302: Introduction to Programming in Java. Lecture 15 CS 302: Introduction to Programming in Java Lecture 15 Class Instances of the class (objects) only valid at runtime Private Instance Methods Instance methods usually public why? If we have an internal

More information

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2) Summary: Chapters 1 to 10 Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email: sharma@cse.uta.edu

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Inheritance Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation

More information

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015/16 INTRODUCTORY PROGRAMMING CMP-0005B Time allowed: 2 hours. Answer BOTH questions from section A and ONE question

More information

ENCAPSULATION AND POLYMORPHISM

ENCAPSULATION AND POLYMORPHISM MODULE 3 ENCAPSULATION AND POLYMORPHISM Objectives > After completing this lesson, you should be able to do the following: Use encapsulation in Java class design Model business problems using Java classes

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

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

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

This week. Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces

This week. Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces This week Tools we will use in making our Data Structure classes: Generic Types Inheritance Abstract Classes and Interfaces This is a lot of material but we'll be working with these tools the whole semester

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

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.

More information

CSIS 10B Lab 2 Bags and Stacks

CSIS 10B Lab 2 Bags and Stacks CSIS 10B Lab 2 Bags and Stacks Part A Bags and Inheritance In this part of the lab we will be exploring the use of the Bag ADT to manage quantities of data of a certain generic type (listed as T in the

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4(b): Inheritance & Polymorphism Lecture Contents What is Inheritance? Super-class & sub class The object class Using extends keyword

More information

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017 Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data

More information

Module Contact: Dr Tony Bagnall, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Tony Bagnall, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 DATA STRUCTURES AND ALGORITHMS CMP-5014Y Time allowed: 2 hours Section A (Attempt all questions: 75 marks) Section

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Name: CS 159 Practice Final Fall 2015

Name: CS 159 Practice Final Fall 2015 Name: CS 159 Practice Final Fall 2015 CS 159, Fall 2015 Final Exam Section 02 Page 2 of 16 1. Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen

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

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

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Inheritance Hierarchy; Polymorphism Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin q Class

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

Admin. q Admin and recap q Class inheritance

Admin. q Admin and recap q Class inheritance Admin CS 112 Introduction to Programming q Class project Please work on forming teams Inheritance Hierarchy; Polymorphism Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:

More information

More about inheritance

More about inheritance Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting

More information

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN CSSE 220 Day 15 Inheritance Check out DiscountSubclasses from SVN Discount Subclasses Work in pairs First look at my solution and understand how it works Then draw a UML diagram of it DiscountSubclasses

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

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

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

More information

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

BSc. (Hons.) Software Engineering. Examinations for / Semester 2 BSc. (Hons.) Software Engineering Cohort: BSE/04/PT Examinations for 2005-2006 / Semester 2 MODULE: OBJECT ORIENTED PROGRAMMING MODULE CODE: BISE050 Duration: 2 Hours Reading Time: 5 Minutes Instructions

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

1.00 Lecture 13. Inheritance

1.00 Lecture 13. Inheritance 1.00 Lecture 13 Inheritance Reading for next time: Big Java: sections 10.5-10.6 Inheritance Inheritance allows you to write new classes based on existing (super or base) classes Inherit super class methods

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

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE COURSE NAME: OBJECT ORIENTED PROGRAMMING COURSE CODE: OOP521S NQF LEVEL: 6 DATE: NOVEMBER 2015 DURATION: 2 HOURS

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

Name: CS 159 Practice Final Fall 2015

Name: CS 159 Practice Final Fall 2015 Name: CS 159 Practice Final Fall 2015 CS 159, Fall 2015 Final Exam Section 02 Page 2 of 17 1. Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen

More information

C a; C b; C e; int c;

C a; C b; C e; int c; CS1130 section 3, Spring 2012: About the Test 1 Purpose of test The purpose of this test is to check your knowledge of OO as implemented in Java. There is nothing innovative, no deep problem solving, no

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC Topic 7: Inheritance Reading: JBD Sections 7.1-7.6 1 A Quick Review of Objects and Classes! An object is an abstraction that models some thing or process! Examples of objects:! Students, Teachers, Classes,

More information

CSE 1325 Project Description

CSE 1325 Project Description CSE 1325 Summer 2016 Object-Oriented and Event-driven Programming (Using Java) Instructor: Soumyava Das Project III Assigned On: 7/12/2016 Due on: 7/25/2016 (before 11:59pm) Submit by: Blackboard (1 folder

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

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

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

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

The software crisis. code reuse: The practice of writing program code once and using it in many contexts. Inheritance The software crisis software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues:

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

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

Big software. code reuse: The practice of writing program code once and using it in many contexts.

Big software. code reuse: The practice of writing program code once and using it in many contexts. Inheritance Big software software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues: getting

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

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance? CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

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

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

More information

Exam 1 - (20 points)

Exam 1 - (20 points) Exam 1 - (20 points) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your scantron sheet. Each correct answer is worth 1 point (unless otherwise stated).

More information

Polymorphism and Inheritance

Polymorphism and Inheritance Walter Savitch Frank M. Carrano Polymorphism and Inheritance Chapter 8 Objectives Describe polymorphism and inheritance in general Define interfaces to specify methods Describe dynamic binding Define and

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

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Java How to Program, 8/e

Java How to Program, 8/e Java How to Program, 8/e Polymorphism Enables you to program in the general rather than program in the specific. Polymorphism enables you to write programs that process objects that share the same superclass

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant

More information

5/24/12. Introduction to Polymorphism. Chapter 8. Late Binding. Introduction to Polymorphism. Late Binding. Polymorphism and Abstract Classes

5/24/12. Introduction to Polymorphism. Chapter 8. Late Binding. Introduction to Polymorphism. Late Binding. Polymorphism and Abstract Classes Introduction to Polymorphism Chapter 8 Polymorphism and Abstract Classes Slides prepared by Rose Williams, Binghamton University There are three main programming mechanisms that constitute object-oriented

More information

Inheritance (Part 2) Notes Chapter 6

Inheritance (Part 2) Notes Chapter 6 Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

Review of Object-Oriented Concepts in JAVA

Review of Object-Oriented Concepts in JAVA Review of Object-Oriented Concepts in JAVA Object-Oriented Concepts supported by JAVA. Advantages of Object-Orientation. Inheritance. Abstract Classes. Interfaces. Review Questions. Object-Oriented Concepts

More information

REVIEW EXERCISES. Draw an inheritance diagram that shows the relationships between these classes.

REVIEW EXERCISES. Draw an inheritance diagram that shows the relationships between these classes. Review Exercises 367 11. A derived-class pointer can be converted to a base-class pointer. 12. When a virtual function is called, the version belonging to the actual type of the implicit parameter is invoked.

More information

9/10/2018 Programming Data Structures Inheritance

9/10/2018 Programming Data Structures Inheritance 9/10/2018 Programming Data Structures Inheritance 1 Email me if the office door is closed 2 Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same

More information