CS 403/503 Exam 4 Spring 2015 Solution

Size: px
Start display at page:

Download "CS 403/503 Exam 4 Spring 2015 Solution"

Transcription

1 CS 403/503 Exam 4 Spring 2015 Solution Each problem initially scored out of 10 points possible. CS 403 Best 5 answers doubled. (5*20 + 2*10 = 120 possible) CS 503 Best 4 answers doubled. (4*20 + 3*10 = 110 possible) 1. Write the output values that are printed by this Smalltalk code. Be especially careful when determining which value is printed first. x := 30. block1 := [x := (3*x)+1. block2 := [x := x/2. x := 24. block3 := [x>=2. block4 := [Transcript display: x; space. x odd iftrue: block1 iffalse: block2. x := 18. block5 := [block3 whiletrue: block4. block5 value. Transcript display: x; cr. x := List five (or more) most significant ways that Smalltalk differs from C++ and/or Java. Pure OOP: everything is an object (no primitive types), always uses late method binding. Dynamic typing: no static type declarations. Subtypes are based on protocols (which methods are provided) rather than inheritance. Implicit visibility rather than explicit public/private modifiers. Interpreted rather than compiled. No templates, method overloading, etc, because polymorphism is automatic. Blocks provide higher-order (anonymous) functions. No importing of libraries because all classes are always available. Syntax for message sends: unary, binary, and keyword-based. No multiple inheritance (as in C++) and no interfaces (as in Java). Integrated GUI classes with windows, graphics, bitmap display, mouse, browser, etc. Can modify all the predefined classes and methods (but maybe not wise to do this).

2 3. Write a Smalltalk class named Interval whose instances represent continuous finite ranges on the real number line. The class should behave as in the following example. X := Interval new left: 0 right: 4. "X is the interval from 0 to 4" Y := Interval new left: 2 right: 7. "Y is the interval from 2 to 7" Z := Interval new left: 5 right: 11. "Z is the interval from 5 to 11" X length. "returns 4" Y length. "returns 5" Z length. "returns 6" X disjoint: Y. "returns false" X disjoint: Z. "returns true" Y disjoint: X. "returns false" Y disjoint: Z. "returns false" Z disjoint: X. "returns true" Z disjoint: Y. "returns false" X intersects: Y. "returns true" X intersects: Z. "returns false" Y intersects: X. "returns true" Y intersects: Z. "returns true" Z intersects: X. "returns false" Z intersects: Y. "returns true" Object subclass: #Interval. Interval instancevariablenames: 'left right'. Interval extend [ left: a right: b [left:=a. right:=b getleft [^left getright [^right length [^right - left disjoint: other [^(left > other getright) or: [right < other getleft intersects: other [^(left <= other getright) and: [right >= other getleft

3 4. Write two Smalltalk classes, Bag and Set, so that the client code below will behave as shown. Note that a Bag allows duplicate values, but a Set does not. Your classes may use the Node class shown below, but do not use any classes in Smalltalk s predefined Collection hierarchy. Minimize the amount of code you write by using inheritance. b := Bag new init. b add: 10; add: 20; add: 10. b getsize. "returns 3" b count: 10. "returns 2" b count: 20. "returns 1" b count: 30. "returns 0" s := Set new init. s add: 10; add: 20; add: 10. s getsize. "returns 2" s count: 10. "returns 1" s count: 20. "returns 1" s count: 30. "returns 0" Object subclass: #Node. Node instancevariablenames: 'value next'. Node extend [ value: v next: n [value:=v. next:=n getvalue [^value getnext [^next Object subclass: #Bag. Bag instancevariablenames: 'head size'. Bag extend [ init [head:=nil. size:=0 add: v [size:=size+1. head:=node new value: v next: head getsize [^size count: v [ c p c:=0. p:=head. [p isnil whilefalse: [v=p getvalue iftrue: [c:=c+1. p:=p getnext. ^c Bag subclass: Set [ add: v [(self count: v)=0 iftrue: [super add: v

4 5. In Smalltalk, a message sent to a receiver named super is implemented as a message sent to self, except that method search does not begin in the receiver s class as it normally would. Two proposed implementations of super are described below. If these two implementations are equivalent, then explain why both implementations always produce the same result. Otherwise provide a counterexample and show that the two implementations can produce different results. Also state which, if either, of these two implementations is correct. A. Method search begins in the superclass of the receiver s class. B. Method search begins in the superclass of the class that defines the method that sends the message to super. Object subclass: #X. X extend [p [^true X subclass: #Y. Y extend [p [^false q [^super p Y subclass: #Z. z := Z new. Transcript display: z q; cr. Using implementation B, the message (z q) returns true, which is the correct answer. Using implementation A, the message (z q) returns false, which is not correct. Implementation B is correct, but implementation A is not correct. 6. Draw a well-designed object-oriented class inheritance hierarchy that satisfies the is-a relationship (or principle of substitutability ) and that includes these classes: Hawk, Grass, Tree, Reptile, Dog, Mammal, Pine, Cat, Cobra, Poodle, Animal, Rose, Bird, LivingThing, Snake, Oak, Plant, Shark, Lion, Flower, Fish. LivingThing Animal Plant Mammal Reptile Bird Fish Tree Grass Flower Dog Cat Snake Hawk Shark Oak Pine Rose Poodle Lion Cobra

5 7. Trace this (GNU-style) Smalltalk code and show the outputs on the indicated blank lines. Object subclass: #A. A extend [ f: x at: k [x at: k put: 7. self g: x at: k+1 g: x at: k [x at: k put: 8. self h: x at: k+1 h: x at: k [x at: k put: 9. self i: x at: k+1 i: x at: k [x at: k put: 10. self j: x at: k+1 j: x at: k [x at: k put: 11. self k: x at: k+1 k: x at: k [x at: k put: 12 A subclass: #B. B extend [ f: x at: k [x at: k put: 13. self g: x at: k+1 h: x at: k [x at: k put: 14. self i: x at: k+1 j: x at: k [x at: k put: 15. self k: x at: k+1 A subclass: #C. C extend [ g: x at: k [x at: k put: 16. self h: x at: k+1 i: x at: k [x at: k put: 17. self j: x at: k+1 k: x at: k [x at: k put: 18 y := Array new: 6. B new f: y at: 1. y do: [:w w printnl (y collect: [:w 3*w) printnl. ( ) (y select: [:w w even) printnl. ( ) (y inject: 0 into: [:m :n m+n) printnl. 72 z := Array new: 6. C new f: z at: 1. z do: [:w w printnl (z collect: [:w 3*w) printnl. ( ) (z reject: [:w w even) printnl. ( ) (z inject: 0 into: [:m :n m+n) printnl. 78

fohgp siejt karbl mcqdn

fohgp siejt karbl mcqdn CS 403/503 Exam 4 Spring 2017 Solution CS 403 Score is based on your best 8 out of 10 problems. CS 503 Score is based on your best 9 out of 10 problems. Extra credit will be awarded if you can solve additional

More information

CS 403/503 Exam 4 Spring 2017 Name

CS 403/503 Exam 4 Spring 2017 Name CS 403/503 Exam 4 Spring 2017 Name CS 403 Score is based on your best 8 out of 10 problems. CS 503 Score is based on your best 9 out of 10 problems. Extra credit will be awarded if you can solve additional

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

GUI-Based Software Development. The Model/View/Controller Pattern

GUI-Based Software Development. The Model/View/Controller Pattern GUI-Based Software Development The Model/View/Controller Pattern Origins of Personal Computing The most important part of a computer system is the individual human user. - Alan Kay Origins of Personal

More information

Pharo Syntax in a Nutshell

Pharo Syntax in a Nutshell Pharo Syntax in a Nutshell Damien Cassou, Stéphane Ducasse and Luc Fabresse W1S06, 2015 W1S06 2 / 28 Getting a Feel About Syntax In this lecture we want to give you the general feel to get started: Overview

More information

Polymorphism. Arizona State University 1

Polymorphism. Arizona State University 1 Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

Smalltalk FOOP. Smalltalk

Smalltalk FOOP. Smalltalk 2015-03-20 Smalltalk Smalltalk 2015-03-20 Smalltalk 1 First Examples hello Transcript show: Hi World hello5 1 to: 5 do: [:i (Transcript show: Hi World ) cr] hello: times 1 to: times do: [:i (Transcript

More information

Object-oriented Programming. Object-oriented Programming

Object-oriented Programming. Object-oriented Programming 2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

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

Programming II (CS300)

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

More information

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School Class Hierarchy and Interfaces David Greenstein Monta Vista High School Inheritance Inheritance represents the IS-A relationship between objects. an object of a subclass IS-A(n) object of the superclass

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

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

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Some instance messages and methods

Some instance messages and methods Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Inheritance and object compatibility

Inheritance and object compatibility Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can

More information

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

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

More information

Inheritance & Polymorphism

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

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

Object Oriented Paradigm Languages

Object Oriented Paradigm Languages Object Oriented Paradigm Languages The central design goal is to build inherent abstraction into the system, moving all the abstract implementation details from the user level (ad-hoc) to the system level

More information

Smalltalk. Topics. History of Smalltalk. OOP and GUI. Steve Jobs, PARC, Dec Smalltalk 1. The best way to predict the future is to invent it.

Smalltalk. Topics. History of Smalltalk. OOP and GUI. Steve Jobs, PARC, Dec Smalltalk 1. The best way to predict the future is to invent it. Smalltalk The best way to predict the future is to invent it. Alan Kay, 1971 Topics History and significance of Smalltalk Object-oriented programming The Smalltalk language Smalltalk today Additional Examples

More information

CS558 Programming Languages Winter 2013 Lecture 8

CS558 Programming Languages Winter 2013 Lecture 8 OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).

More information

COMP 110/L Lecture 20. Kyle Dewey

COMP 110/L Lecture 20. Kyle Dewey COMP 110/L Lecture 20 Kyle Dewey Outline super in methods abstract Classes and Methods Polymorphism super in Methods Recap You ve seen super in constructors... Recap You ve seen super in constructors...

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

QUESTIONS FOR AVERAGE BLOOMERS

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

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING YEAR/SEM:II & III UNIT I 1) Give the evolution diagram of OOPS concept. 2) Give some

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

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

Object Orientated Programming Details COMP360

Object Orientated Programming Details COMP360 Object Orientated Programming Details COMP360 The ancestor of every action is a thought. Ralph Waldo Emerson Three Pillars of OO Programming Inheritance Encapsulation Polymorphism Inheritance Inheritance

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

abstract binary class composition diamond Error Exception executable extends friend generic hash implementation implements

abstract binary class composition diamond Error Exception executable extends friend generic hash implementation implements CS365 Midterm 1) This exam is open-note, open book. 2) You must answer all of the questions. 3) Answer all the questions on a separate sheet of paper. 4) You must use Java to implement the coding questions.

More information

Squeak Object Model. Technion - Israel Institute of Technology. Updated: Spring Object-Oriented Programming 1

Squeak Object Model. Technion - Israel Institute of Technology. Updated: Spring Object-Oriented Programming 1 Squeak Object Model Technion - Israel Institute of Technology Updated: Spring 2015 236703 - Object-Oriented Programming 1 Agenda Class exploring Class object, default / common behaviors Objects equality

More information

Inheritance. Transitivity

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

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Review 2: Object-Oriented Programming Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Review 2: Object-Oriented Programming 1 / 14 Topics

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship The "is-a" Relationship Object classification

More information

Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap In this chapter we will examine how differences in static and dynamic features effect object-oriented programming

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship Object classification is typically hierarchical.

More information

Type Hierarchy. Lecture 6: OOP, autumn 2003

Type Hierarchy. Lecture 6: OOP, autumn 2003 Type Hierarchy Lecture 6: OOP, autumn 2003 The idea Many types have common behavior => type families share common behavior organized into a hierarchy Most common on the top - supertypes Most specific at

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 and Polymorphism. CS180 Fall 2007

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

More information

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation CSE 452: Programming Languages Data Abstraction and Object-Orientation Previous Lecture Abstraction Abstraction is the elimination of the irrelevant and the amplification of the essential Robert C Martin

More information

2. Classes & Inheritance. Classes. Classes. Éric Tanter Objects and Design in Smalltalk. How do you create objects?

2. Classes & Inheritance. Classes. Classes. Éric Tanter Objects and Design in Smalltalk. How do you create objects? Objects and Design in Smalltalk 2. Classes & Inheritance Éric Tanter etanter@dcc.uchile.cl 1 Classes How do you create objects? Ex-nihilo in prototype-based languages With a class in class-based languages

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

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

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will start to investigate the concepts of inheritance and substitution: The intuitive and practical

More information

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula CS 242 Simula 67 Simula and Smalltalk John Mitchell First object-oriented language Designed for simulation Later recognized as general-purpose prog language Extension of Algol 60 Standardized as Simula

More information

First IS-A Relationship: Inheritance

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

More information

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018 1 Terminology 1 2 Class Hierarchy Diagrams 2 2.1 An Example: Animals...................................

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

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

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

More information

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION Course Title: Java Technologies Grades: 10-12 Prepared by: Rob Case Course Unit: What is Java? Learn about the history of Java. Learn about compilation & Syntax. Discuss the principles of Java. Discuss

More information

Subtyping (Dynamic Polymorphism)

Subtyping (Dynamic Polymorphism) Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT). Encapsulation OOP: Introduction 1 Pure Object-Oriented Languages Five rules [Source: Alan Kay]: Everything in

More information

Object Oriented Programming and Design in Java. Session 10 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 10 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 10 Instructor: Bert Huang Announcements Homework 2 due Mar. 3rd, 11 AM two days Midterm review Monday, Mar. 8th Midterm exam Wednesday, Mar. 10th

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

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING SUB CODE / SUBJECT: CS1203 / Object oriented programming YEAR / SEM: II / III QUESTION BANK UNIT I FUNDAMENTALS PART-A (2 MARKS) 1. What is Object Oriented

More information

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

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

More information

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

2. The object-oriented paradigm

2. The object-oriented paradigm 2. The object-oriented paradigm Plan for this section: Look at things we have to be able to do with a programming language Look at Java and how it is done there Note: I will make a lot of use of the fact

More information

Object Oriented Programming: Based on slides from Skrien Chapter 2

Object Oriented Programming: Based on slides from Skrien Chapter 2 Object Oriented Programming: A Review Based on slides from Skrien Chapter 2 Object-Oriented Programming (OOP) Solution expressed as a set of communicating objects An object encapsulates the behavior and

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

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

More Relationships Between Classes

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

More information

Introduction to Seaside

Introduction to Seaside Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com Version 2.01 on 20 July 2009 This document is copyright 2008, 2009 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. This work

More information

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

The Sun s Java Certification and its Possible Role in the Joint Teaching Material The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified

More information

Object Oriented Issues in VDM++

Object Oriented Issues in VDM++ Object Oriented Issues in VDM++ Nick Battle, Fujitsu UK (nick.battle@uk.fujitsu.com) Background VDMJ implemented VDM-SL first (started late 2007) Formally defined. Very few semantic problems VDM++ support

More information

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

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

More information

Java 8 Programming for OO Experienced Developers

Java 8 Programming for OO Experienced Developers www.peaklearningllc.com Java 8 Programming for OO Experienced Developers (5 Days) This course is geared for developers who have prior working knowledge of object-oriented programming languages such as

More information

CS365 Midterm -- Spring 2019

CS365 Midterm -- Spring 2019 CS365 Midterm -- Spring 2019 1. This exam is closed-note, closed-book. 2. You must answer all of the questions. 3. The exam has 120 points and you will be scored out of 120 points. For example, if you

More information

CSE 143. "Class Relationships" Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization

CSE 143. Class Relationships Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization Class Relationships and Inheritance [Chapter 8, pp.343-354] "Class Relationships" is the title of Chapter 8 One class may include another as a member variable Date" used inside "Performance" Called a "has-a"

More information

More On inheritance. What you can do in subclass regarding methods:

More On inheritance. What you can do in subclass regarding methods: More On inheritance What you can do in subclass regarding methods: The inherited methods can be used directly as they are. You can write a new static method in the subclass that has the same signature

More information

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail

More information

Today. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods

Today. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods Today CSE341: Programming Languages Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins Alan Borning Spring 2018 Dynamic dispatch aka late binding aka virtual method calls Call to self.m2() in

More information

Classes, Objects, and OOP in Java. June 16, 2017

Classes, Objects, and OOP in Java. June 16, 2017 Classes, Objects, and OOP in Java June 16, 2017 Which is a Class in the below code? Mario itsame = new Mario( Red Hat? ); A. Mario B. itsame C. new D. Red Hat? Whats the difference? int vs. Integer A.

More information

3. Object-Oriented Databases

3. Object-Oriented Databases 3. Object-Oriented Databases Weaknesses of Relational DBMSs Poor representation of 'real world' entities Poor support for integrity and business rules Homogenous data structure Limited operations Difficulty

More information

Strict Inheritance. Object-Oriented Programming Spring 2008

Strict Inheritance. Object-Oriented Programming Spring 2008 Strict Inheritance Object-Oriented Programming 236703 Spring 2008 1 Varieties of Polymorphism P o l y m o r p h i s m A d h o c U n i v e r s a l C o e r c i o n O v e r l o a d i n g I n c l u s i o n

More information

Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction

Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction Class Interaction There are 3 types of class interaction. One

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

Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס

Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע י דר גרא וייס Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס 2 Roadmap In this chapter we will examine how differences

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Introduction to Computers and Programming Languages CS 180 Sunil Prabhakar Department of Computer Science Purdue University 1 Objectives This week we will study: The notion of hardware and software Programming

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

More information

Introduction to Smalltalk

Introduction to Smalltalk Introduction to Smalltalk Randal L. Schwartz, merlyn@stonehenge.com Version 1.01 on 20 July 2009 This document is copyright 2009 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. This work is

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 10a Andrew Tolmach Portland State University 1994-2017 Object-oriented Programming Programs are structured in terms of objects: collections of variables

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

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM) DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR 2018-19 (ODD SEM) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING SUB: OBJECT ORIENTED PROGRAMMING SEM/YEAR: III SEM/ II YEAR

More information

Part V. Object-oriented Programming. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Part V. Object-oriented Programming. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26, Part V Object-oriented Programming Compact Course @ Max-Planck, February 16-26, 2015 65 What Is an Object? Compact Course @ Max-Planck, February 16-26, 2015 66 What Is an Object? a car a cat a chair...

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

Object Orientated Analysis and Design. Benjamin Kenwright

Object Orientated Analysis and Design. Benjamin Kenwright Notation Part 2 Object Orientated Analysis and Design Benjamin Kenwright Outline Review What do we mean by Notation and UML? Types of UML View Continue UML Diagram Types Conclusion and Discussion Summary

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