CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers

Size: px
Start display at page:

Download "CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers"

Transcription

1 CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers This was a 100-minute open-book test. There were a total of 105 points on this test.. If you answered more than 100% worth of questions correctly, your score was 100%. Question 1. Using the following scenario, create CRC index cards using the CRC method. Scenario: Jack s Sue's boss his résumé. Note: In this scenario Jack obtains the boss s address by asking Sue for it (a) (4 points) The CRC method states that to determine the classes, you should search for all nouns in the scenario, and convert them to class names. Each class name is placed on a separate index card. What would be reasonable names for the classes in this scenario? Answer: Applicant, Employee, Boss, Résumé Applicant Employee Boss Résumé (b) (1 point) The CRC method states that the verb(s) in the scenario will represent the responsibilities. Add the responsibilities to the appropriate CRC cards. Answer: Applicant s a message (c) (4 points) The CRC method states that the collaborators are the other cards that must be accessed to carry out the responsibility. What two things does Jack need in order to carry out the responsibility to ? Answer: Jack needs access to his resume (Résumé card needed) He also needs the boss s address. (d) (3 points) Add responsibilities and collaborators on the appropriate cards to show how Jack can accomplish his objective in part (c). Answer: As was mentioned in the problem, the only way Jack can get the address is to ask Sue. (Employee card needed) This action gives Applicant another responsibility (Ask for boss s address), and a responsibility for Employee (Furnish address) Applicant s a message Ask for Boss s address Résumé, Boss Employee Employee Furnish address 1

2 Question 2. (3 points each) Consider the code segment below. Another portion of the code reads stock prices from a database into an array that holds prices for each stock for each day in the past month. Identify at least three examples of inelegance, according to how elegance is described in Skrien Chapter 4: Elegance and Methods. /****************************************************** * The class is responsible for holding information on a position * * in a given stock. * *******************************************************/ public class Stock { private String s; private float currpriceindollarsofaparticularstock; private float prevpriceindollarsofaparticularstock; private int numshares; /************************************************ * Constructor * * s -- the Stock symbol * * currpriceindollarsofaparticularstock * * -- the current price per share * * prevpriceindollarsofaparticularstock * * -- the previous day s price per share * * numshares is the number of shares currently owned * ************************************************/ public Stock(String s, float pps, int sh) { this.s = s; currpriceindollarsofaparticularstock = pps; prevpriceindollarsofaparticularstock = 0; numshares = sh; /************************************************ * This method returns the symbol of this stock * ************************************************/ public String getsymbol() { return s;... /************************************************ * This method returns the change in price per share. * ************************************************/ public int getpricechange() { return currpriceindollarsofaparticularstock prevpriceindollarsofaparticularstock; Answer 2. The following 3 answers are formatted as follows: Original code Changed code Explanation 1. private String s; private String symbol; the variable s is not descriptive enough (answer given is a good option). 2. private float currpriceindollarsofaparticularstock; private float pricepershare; the variable name is to long and should be shortened to something like the suggested answer. 3. private float prevpriceindollarsofaparticularstock. It is not clear that this variable is needed, if it is used only here. It could be replaced by an access to the appropriate array value. 3a. getpricechange() ==> this method should not be implemented in this class. It does not make sense to keep a separate variable for the previous day s price per share when the past 30 days of prices is needed for another portion of the system. The price change can easily be calculated using the structure used for storing the 30-day history of prices. 2

3 Question 3. (5 points each) Suppose you need to create a class that will keep track of service records for an automobile. Service records may include oil changes, tire replacements, tire maintenance (rotation, balance, flat repairs). (a) Modify the following code to adhere to the open-closed principle and explain. public class MaintenanceRecords{ public Object [] records; public int money; // money spent public addoilchange(oilc o); public addtirerepl(tirer r); public addtiremaint(timem m); Answer: To keep the class from being modified (closed) data should be kept private. private Object [] records; private int money; (b) From the standpoint of accessibility, this class is inelegant in other ways. What happens in case you decide to also keep track of repairs too? Explain. Answer: The add methods do essentially the same thing different kinds of maintenance and repairs. But a separate method is needed for each. This becomes cumbersome when there are a lot of potential items. Better we should create another abstract class Service that can hold data for any kind of service record. Then the 3 add methods can be replaced by public addservice(service c); Question 4. (6 points) Suppose you have a class with the following methods public class DatabaseParser { ParseDirectoryMapFile(); // parse directory map file ParsePasswordFile(); // parse user file ParseReviewDataFile(); // parse review data file ParseTeamFile(); // parse team file CalculateGrade(); CalulateRelativeGrade(); (a) Is this a well-formed class? Why or why not? Answer: No. A well-formed class should be responsible for doing one thing and do it well. A DatabaseParser class should do parser of only database file and nothing else, but it not only parsing the file and also calculate dividing and relative grade. Furthermore, it is not a good idea to have all of the Parse methods in a single class. They evidently relate to parsing different kinds of files, and thus, the implementation would better be placed in the classes for these particular files, so that the DatabaseParser class could simply execute mydirectorymapfile.parse(); mypasswordfile.parse();, etc. 3

4 (b) If this is an ill-formed class, tell how to make it into well-formed class. We should modify the DatabaseParser class by removing the calculategrade and calculaterelativegrade functions, and put them into a different class. public class DatabaseParser { ParseDirectoryMapFile(); // parse directory map file ParsePasswordFile(); // parse user file ParseReviewDataFile(); // parse review data file ParseTeamFile(); // parse team file public class Caculator { CalculateGrade(); CalulateRelativeGrade(); Question 5. (2 points per blank) There are many issues to consider in deciding whether to use an interface or an abstract class. The table below lists some of those issues. Fill in the blanks with a description of how an interface or an abstract class would affect the design. For example, in the first row, the blanks have been filled in by explaining how, if at all, an interface helps achieve code reuse, and how an abstract class helps achieve code reuse. Design consideration Interface Abstract class Facilitating code reuse Providing a common implementation for functionality in various classes Adding extra methods to each of the classes Since an interface by definition does not include any implementation, it does not facilitate code reuse. An interface provides/enforces only the signature of the methods within it, so the actual implementations of the methods may be completely different. This can be good, if the various implementers really are that different, or it can be bad if the divergence is unnecessary. Any class implementing an interface must implement all of the methods in the interface, or it will not compile. Therefore you cannot add any methods to the interface without breaking all of the classes which have already implemented it. To the extent that common functions for the class hierarchy are implemented in the superclass, code reuse is achieved. Classes implemented within the abstract class, if not overridden by its subclasses, will have the implementation intended by the designer of the abstract class. Of course, if the designer is not able to anticipate the likely uses of the class, this can become a limiting factor, requiring subclasses to override the "common" implementation. An abstract class can contain implementations for any/all of its methods. Therefore, if the system evolves so that it makes sense to add functionality to the class hierarchy, methods can be added to the abstract class without breaking classes that extend it. If it does not make sense to actually implement the new method, a "stub" can be provided in the superclass. Design consideration Interface Abstract class 4

5 Inheriting from other classes Hiding information from other classes (encapsulation) Implementing an interface does not consume the single inheritance opportunity that a Java class has. Thus an implementing class can aggregate the functionality of many interfaces without running into any inheritance limitations. Because the interface cannot contain any implementation and can only contain public static final variables (i.e. public constants), implementing it does not give the implementing class access to any of the internal data of the interface. Using an abstract class at the top of the hierarchy forces subclasses to use their sole inheritance opportunity to extend the abstract class. An abstract class can contain nonpublic members (methods and data). If the abstract class contains any such members, they are potentially exposed to all of the subclasses. This can be controlled by proper use of scope definitions. Question 6. Suppose a Java program includes these classes: public class A { public void m(a a) {... public class B extends A{... (a) (1 point) Is it legal, in class B, to define a method Yes or no? Answer: Yes. public void m(b b) {...? (b) (2 points) Is this a case of overloading or overriding? Answer: Overloading. (c) (4 points) Given this definition of m(b)in class B, is it possible to send a message to an object of class B (e.g., B myb = new B()), and have class A s method m(a) called? If so, give a statement that causes A s method m to be invoked on myb. Answer: Yes. myb.m(new A()) will do this. (d) (1 point) Assuming that method m(b) has been defined as in part (a), it also legal, in class B, to define a method Yes or no? Answer: Yes. public void m(a a) {...? 5

6 (e) (2 points) Is this a case of overloading or overriding? Answer: Overriding. (f) (4 points) Given these definitions of m(b)and m(b)in class B, is it possible to send a message to an object of class B (e.g., B myb = new B()), and have class A s method m(a) called? If so, give a statement that causes A s method m to be invoked on myb. Answer: No, it is no longer possible, because B defines its own methods for both parameter type A and parameter type B. Question 7. One of the Extreme Programming practices is collective code ownership. (a) (2 points each) List two things that are wrong with individual code ownership, and explain why they are bad. Answer: You have to negotiate with someone if you want to change the interface. There is pressure to get the interface done early so the rest of the project can proceed. If the programmer responsible for the code leaves the project, it is difficult to find someone competent to take over. The owner of a class may veto a change, only to have others design around it, which worsens the design in general. (b) (4 points) Explain how at least two other practices of XP make collective code ownership possible. Answer: Pair programming assists other programmers in learning the code. Test-first development assures that there will be ready-made tests for the code, so a programmer who changes it easily make sure that it still does what it s supposed to. Continuous integration prevents any programmer from taking code and changing it a lot without informing other members of the team. Question 8. Here is the requirements statement for a system. Requirements for the bus navigator system: The mission is to allow students to plan trips around NCSU and Raleigh by bus. Each rider specifies an origination stop and a destination stop. The system presents a list of departure times, arrival times, and transfer points, and a map of the trip. Each item on the list consists of one or more of trip segments. Each trip segment consists of a departure point and time, and an arrival point and time. If it would significantly reduce the time of the trip, the system may suggest walking between two nearby stops. Each segment may be on a Wolfline bus, a CAT bus, or a TTA bus. Each bus has a schedule, which is a set of trips, with each trip consisting of a set of stops and times. The fare is 0 on a Wolfline bus, $1 on a CAT bus, and $2 ($2.50 for express) on a TTA bus. The system calculates the total cost of the trip by adding the cost of the individual segments. From among the italicized nouns in the list above 6

7 (a) (1 point each) Choose four that constitute different key abstractions of the system, and should therefore be implemented as classes of the same name as the noun. Answer: Possibilities include stop, map, segment, walk, bus, any of the three kinds of buses, schedule, and trip. (b) (3 points each) Choose two that are not key abstractions and therefore should not be implemented as classes of the same name as the noun. Explain why they are not key abstractions. Answer: Student and rider are not key abstractions because there is no reason for them to be represented within the system (a client of the system may be a key abstraction, but there is no good reason for calling a client a student or rider, since a client is not necessarily either one). Departure point and arrival point are not key abstractions, because they are just particular stops. Time is not a key abstraction of the system, because the language undoubedly provides a way of representing it, which can simply be used by our system. Cost is not a key abstraction, because it is just a numeric value. Some people said that one term or another is not a key abstraction simply because it is an attribute of another class. This does not show that it s not a key abstraction. Abstractions such as Bus, Schedule, and Trip are all attributes of some class; otherwise it wouldn t be possible to reference them. (c) (2 points) Is any of your key abstractions a subclass of another key abstraction? Explain. Answer: Yes. Wolfline bus, CAT bus, and TTA bus are subclasses of bus, because each one has all the attributes of bus, but a different way of calculating a fare. (d) (3 points) If there is a subclass relationship in part (c), are there any abstract methods? In which class would they be implemented? Answer: fare, implemented in class Bus, would be an abstract method. (e) (4 points) Which one of the terms representing a key abstraction is used ambiguously in the requirements? Identify all the different senses in which the term is used. Answer: The term trip is used in two different senses: as a set of segments that a rider takes to get to the destination, and as a set of stops that a bus passes on its itinerary. Ambiguous is not the same as a synonym. Two terms that mean the same, e.g., stop and point may be synonyms, but they are not ambiguous. (f) (6 points; 3 points each) Suppose that our system includes a (bus) Trip class. Based on the requirement statement above, identify two responsibilities and the collaborator(s), if any, for each of them. (Use the back of the page if you need more room.) Answer: Responsibility Collaborator Know your stops Know your stopping times Stop There are also other possibilities. 7

8 Several students said that knowing the fare was a responsibility of the Trip class. But this is really a responsibility of the passenger s trip, not the bus s. On some buses, the fare varies according to distance traveled. So the Bus can t, in general, know what the fare is. (g) (5 points) Sketch a format for the output that the system might provide to the user. You don t need to draw a map, but do suggest how the list of departure and arrival points and times and transfer points should be presented to the user. Answer: Here is one possibility. From: College of Textiles To: UNC Hospital Fare: $2.00 Lv. Bus College of Textiles 7:20 AM Wolfline #2A-Centennial Campus 7:50 AM Wolfline #2A-Centennial Campus 8:20 AM Wolfline #2A-Centennial Campus Arr. Hill Library Lv. Hill Library Bus 7:33 AM 7:36 AM TTA #101A Raleigh to RTP 8:03 AM 8:06 AM TTA #101A Raleigh to RTP 8:33 AM 8:36 AM TTA #101A Raleigh to RTP Arr. RTP Bus Center Lv. RTP Bus Center Bus 8:10 AM 8:15 AM TTA 401B- RTP to Chapel Hill to Durham 8:40 AM 8:45 AM TTA 401B- RTP to Chapel Hill to Durham 9:10 AM 9:15 AM TTA 401B- RTP to Chapel Hill to Durham Arr. UNC Hospital 8:49 AM 9:19 AM 9:49 AM I leave the map to your imagination! Grade summary High 100 Mean Low 45 Std. Dev Quartiles (74, 83, 88) 8

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

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

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

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

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

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

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

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Comp-304 : Object-Oriented Design What does it mean to be Object Oriented?

Comp-304 : Object-Oriented Design What does it mean to be Object Oriented? Comp-304 : Object-Oriented Design What does it mean to be Object Oriented? What does it mean to be OO? What are the characteristics of Object Oriented programs (later: OO design)? What does Object Oriented

More information

Object-Oriented Design

Object-Oriented Design Software and Programming I Object-Oriented Design Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Discovering classes and methods Relationships between classes An object-oriented

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

CS 251 Intermediate Programming Methods and Classes

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

More information

CS 251 Intermediate Programming Methods and More

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

More information

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

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

STUDENT LESSON A5 Designing and Using Classes

STUDENT LESSON A5 Designing and Using Classes STUDENT LESSON A5 Designing and Using Classes 1 STUDENT LESSON A5 Designing and Using Classes INTRODUCTION: This lesson discusses how to design your own classes. This can be the most challenging part of

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

Object- Oriented Design with UML and Java Part I: Fundamentals

Object- Oriented Design with UML and Java Part I: Fundamentals Object- Oriented Design with UML and Java Part I: Fundamentals University of Colorado 1999-2002 CSCI-4448 - Object-Oriented Programming and Design These notes as free PDF files: http://www.softwarefederation.com/cs4448.html

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

Chapter 5: Structural Modeling

Chapter 5: Structural Modeling Chapter 5: Structural Modeling Objectives Understand the rules and style guidelines for creating CRC cards, class diagrams, and object diagrams. Understand the processes used to create CRC cards, class

More information

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super

Back to ObjectLand. Contents at: Chapter 5. Questions of Interest. encapsulation. polymorphism. inheritance overriding inheritance super korienekch05.qxd 11/12/01 4:06 PM Page 105 5 Back to ObjectLand Contents at: Chapter 5 #( encapsulation polymorphism inheritance overriding inheritance super learning the class hierarchy finding classes

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

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

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

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes Java Curriculum for AP Computer Science, Student Lesson A20 1 STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes INTRODUCTION:

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

Declarations and Access Control SCJP tips

Declarations and Access Control  SCJP tips Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for

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

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

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

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

Introduction to Programming Using Java (98-388)

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

More information

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE Speaking the Language of OO COURSE INFO Instructor : Alper Bilge TA : Gökhan Çıplak-Ahmet Alkılınç Time : Tuesdays 2-5pm Location

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

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

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

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

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

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java

Object-Oriented Software Engineering Practical Software Development using UML and Java Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes Lecture 5 5.1 What is UML? The Unified Modelling Language is a standard graphical

More information

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017 Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

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

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

POFT 2301 INTERMEDIATE KEYBOARDING LECTURE NOTES

POFT 2301 INTERMEDIATE KEYBOARDING LECTURE NOTES INTERMEDIATE KEYBOARDING LECTURE NOTES Be sure that you are reading the textbook information and the notes on the screen as you complete each part of the lessons in this Gregg Keyboarding Program (GDP).

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

Type Checking in COOL (II) Lecture 10

Type Checking in COOL (II) Lecture 10 Type Checking in COOL (II) Lecture 10 1 Lecture Outline Type systems and their expressiveness Type checking with SELF_TYPE in COOL Error recovery in semantic analysis 2 Expressiveness of Static Type Systems

More information

ECE 122. Engineering Problem Solving with Java

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

More information

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

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

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

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

[ L5P1] Object-Oriented Programming: Advanced Concepts

[ L5P1] Object-Oriented Programming: Advanced Concepts [ L5P1] Object-Oriented Programming: Advanced Concepts Polymorphism Polymorphism is an important and useful concept in the object-oriented paradigm. Take the example of writing a payroll application for

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

CS 1302 Chapter 9 (Review) Object & Classes

CS 1302 Chapter 9 (Review) Object & Classes CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state

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

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized

More information

Lecture 5: Inheritance

Lecture 5: Inheritance McGill University Computer Science Department COMP 322 : Introduction to C++ Winter 2009 Lecture 5: Inheritance Sami Zhioua March 11 th, 2009 1 Inheritance Inheritance is a form of software reusability

More information

Spring % of course grade

Spring % of course grade Name SOLUTION Final Score 10 ID Extra Credit Section (circle one): MW 8:30-9:50 TTh 9:30-10:50 TTh 11:00-12:20 10% of course grade 2 1. Anonymous Inner Classes In lecture we walked through the following:

More information

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018 Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside

More information

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

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

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

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

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: Cohesion and Coupling, Mutable, Inheritance Screen Layouts. Object-Oriented Design CRC Cards - UML class diagrams

Review: Cohesion and Coupling, Mutable, Inheritance Screen Layouts. Object-Oriented Design CRC Cards - UML class diagrams Review: Cohesion and Coupling, Mutable, Inheritance Screen Layouts Software methodologies Extreme Programming Object-Oriented Design CRC Cards - UML class diagrams Analysis Design Implementation Software

More information

CS 215 Software Design Sample midterm solutions

CS 215 Software Design Sample midterm solutions Software Design Sample midterm solutions 1. The administration at Happy Valley School District is redesigning the software that manages information about its students. It has identified an abstract class

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

Lecture 4: Extending Classes. Concept

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

More information

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance Handout written by Julie Zelenski, updated by Jerry. Inheritance is a language property most gracefully supported by the object-oriented

More information

6.170 Recitation #5: Subtypes and Inheritance

6.170 Recitation #5: Subtypes and Inheritance 6.170 Recitation #5: Subtypes and Inheritance What is true subtyping? True Subtyping is not exactly the same as Inheritance. As seen in an earlier lecture, class A is a true subtype of class B if and only

More information

CSE wi Final Exam 3/12/18. Name UW ID#

CSE wi Final Exam 3/12/18. Name UW ID# Name UW ID# There are 13 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

5.6.1 The Special Variable this

5.6.1 The Special Variable this ALTHOUGH THE BASIC IDEAS of object-oriented programming are reasonably simple and clear, they are subtle, and they take time to get used to And unfortunately, beyond the basic ideas there are a lot of

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

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm Assignment 2 Solutions This document contains solutions to assignment 2. It is also the Marking Rubric for Assignment 2 used by the TA as a guideline. The TA also uses his own judgment and discretion during

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

IT101. Inheritance, Encapsulation, Polymorphism and Constructors IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

Example: Count of Points

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

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

Mobile App:IT. Methods & Classes

Mobile App:IT. Methods & Classes Mobile App:IT Methods & Classes WHAT IS A METHOD? - A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. -

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

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM

INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM INCORPORATING ADVANCED PROGRAMMING TECHNIQUES IN THE COMPUTER INFORMATION SYSTEMS CURRICULUM Charles S. Saxon, Eastern Michigan University, charles.saxon@emich.edu ABSTRACT Incorporating advanced programming

More information

CS-202 Introduction to Object Oriented Programming

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

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 4&5: Inheritance Lecture Contents What is Inheritance? Super-class & sub class The object class Using extends keyword @override keyword

More information

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question) CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers

More information

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models CS 494 Object-Oriented Analysis & Design UML Class Models Overview How class models are used? Perspectives Classes: attributes and operations Associations Multiplicity Generalization and Inheritance Aggregation

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

UCLA PIC 20A Java Programming

UCLA PIC 20A Java Programming UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002

More information

1 of 5 3/28/2010 8:01 AM Unit Testing Notes Home Class Info Links Lectures Newsgroup Assignmen [Jump to Writing Clear Tests, What about Private Functions?] Testing The typical approach to testing code

More information

Programming in C# Inheritance and Polymorphism

Programming in C# Inheritance and Polymorphism Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data

More information

CS112 Lecture: Extending Classes and Defining Methods

CS112 Lecture: Extending Classes and Defining Methods Objectives: CS112 Lecture: Extending Classes and Defining Methods Last revised 1/9/04 1. To introduce the idea of extending existing classes to add new methods 2. To introduce overriding of inherited methods

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

CLASSES AND OBJECTS IN JAVA

CLASSES AND OBJECTS IN JAVA Lesson 8 CLASSES AND OBJECTS IN JAVA (1) Which of the following defines attributes and methods? (a) Class (b) Object (c) Function (d) Variable (2) Which of the following keyword is used to declare Class

More information

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance. Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit III Inheritance The mechanism that allows us to extend the definition of a class without making

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