Introduction and Review of Java: Part 2

Size: px
Start display at page:

Download "Introduction and Review of Java: Part 2"

Transcription

1 Introduction and Review of Java: Part 2 Fundamental Concepts (Principles) of Object Oriented Programming Java s implementation of Object Oriented Programming 1of 59

2 WHAT IS OBJECT ORIENTED PROGRAMMING? OOP was invented to mitigate the increasing complexity of software trying to make software simpler and more manageable. The Object Oriented approach is to view software the same way we view the world easier for us to understand. OOP is a way of thinking about how to create computer programs to solve problems Everything is an object, and objects communicate between each other and collaborate to implement tasks. Consider how we might go about handling a realworld situation and then ask how we could design software to do the same. 2of 59

3 ILLUSTRATION OF OO CONCEPTS SENDING FLOWERS TO A FRIEND Consider the problem of sending flowers to a friend who lives in a different city. Chris is sending flowers to Robin. Chris can t deliver them directly. So Chris uses the services of the local Florist. Chris tells the Florist (named Fred) Robin s address, how much to spend, and the type of flowers to send. Fred contacts a florist in Robin s city, who arranges the flowers, then contacts a driver, who delivers the flowers. 3of 59

4 COMMUNITY OF AGENTS (OBJECTS) HELPING DELIVER FLOWERS Chris Fred:Florist :Wholesaler :Grower :Gardener Robin sflorist :FlowerArranger Robin :DeliveryPerson UML INSTANCE DIAGRAM 4of 59

5 NOTES ON EXAMPLE (1) Each agent has additional things (responsibilities) that it can do requests that it can fill out Set of responsibilities is called the object s protocol. Each agent has data that belongs to itself data that it must remember to manage its state Example: Fred must remember the transaction with Chris and with Robin s florist. Fred operates on his data, exclusively data encapsulation. 5of 59

6 NOTES ON EXAMPLE (2) A requesting agent does not care about how the receiving agent implements a request Information hidingand abstraction Different receiving agents may implement a request in different ways Polymorphism. Each requesting agent must trust the receiving agent to fulfill the request appropriately Reuse of existing components. 6of 59

7 NOTES ON EXAMPLE (3) Agents of the same type are similar, and they may be classified as a class Other Florists, like Jane, Samantha, and Fernando Other Gardeners, etc. Class for Florists, Gardeners, DeliveryPerson, etc. Each class can be organized into a hierarchy Fred is a Florist, Florist is Shopkeeper, Shopkeeper is a Human, Human is a Mammal, Mammal is an Animal, Animal is a Material Object. Classes inherit properties of upper layer classes Inheritance Hierarchy. 7of 59

8 CATEGORIES SURROUNDING FRED MaterialObject Animal Mammal Human Shopkeeper Florist NON STANDARD DIAGRAM UML CLASS DIAGRAM (SHOWING INHERITANCE) 8of 59

9 A CLASS IHERITANCE HIERARCHY UML CLASS DIAGRAM MaterialObject Animal Plant Mammal Flower Dog Human Platypus Carnation Shopkeeper Artist Dentist Florist Potter 9of 59

10 FUNDAMENTAL CHARACERISTICS (PRINCIPLES) OF OBJECT ORIENTED (OO) PROGRAMMING 1. Everything is an object Each object has a set of responsibilities (behavior), a set of things it can do Each object has it own data, which it manages, exclusively. 2. Objects send messages (requests) to one another. A message may contain additional information needed to carry out the request. Messages are usually implemented as methods, a way in which a request is implemented Additional information is encoded in the argument list of the method. 10 of 59

11 FUNDAMENTAL CHARACERISTICS (PRINCIPLES) OF OBJECT ORIENTED (OO) PROGRAMMING 3. Classes may be organized in an inheritance hierarchy, where higher layers contain more general information and lower layers contain more specific information about the class. Lower layer classes in the hierarchy inherit properties of higher layer classes in the hierarchy. 4. Reuse and reusable components 5. Information hiding and abstraction 6. Polymorphism 11 of 59

12 JAVA OO PROGRAMMING Object An object has state and behavior. Class A class is a blueprint from which objects are created. Inheritance Inheritance provides a powerful and natural mechanism for organizing and structuring your software. Interface An interface is a contract between a class and the outside world. Package A package is a namespace for organizing classes and interfaces in a logical manner. 12 of 59

13 WHAT IS AN OBJECT? Object Oriented Technology views software in the same way we view real world objects: Real world objects share two characteristics They all have state and behavior. Examples of real world objects Dogs State: name, color, breed, hungry Behavior: barking, fetching, wagging tail. Bicycles State: current gear, current pedal cadence, current speed Behavior: changing gear, changing pedal cadence, applying brakes. 13 of 59

14 WHAT IS AN OBJECT? Desktop radio States: on, off, current volume, current station Behavior: turn on, turn off, increase volume, decrease volume, seek, scan, and tune. Some objects will also contain other objects Example: Automobiles States: color, make, model, Transmission, weight, etc. Behavior: start, brake, increase speed, etc. Transmission States: park, reverse, drive, etc. Behavior: change gears, increase speed, etc. 14 of 59

15 A SOFTWARE OBJECT IN JAVA Software objects consist of state and related behavior Stores its state in fields (variables) Exposes its behavior through methods. Methods Operate on an object s internal state, and Serve as the primary mechanism for object to object communication. Data Encapsulation Hiding internal state and requiring all interaction to be performed through an object s methods is known as data encapsulation a fundamental principle of object oriented programming. 15 of 59

16 A SOFTWARE OBJECT REPRESENTATION The object remains in control of how the outside world is allowed to use it. OF A BICYCLE For example, if the bicycle only has 6 gears, a method to change gears could reject any value that is less than 1 or greater than of 59

17 BENEFITS OF OBJECT ORIENTATION Modularity The source code for an object can be written and maintained independently of the source code for other objects. Once written, the source code for an object can be easily passed around inside the system. Information hiding By interacting only with an object s methods, the details of its internal implementation remain hidden from the outside world Reduces complexity. The details of its internal implementation can be changed without affecting other objects that use it. 17 of 59

18 BENEFITS OF OBJECT ORIENTATION Data Encapsulation Only the object's own methods can directly inspect or manipulate its fields. Decreases complexity because we don t have to worry about any code changing the internal state of an object, except for the object s own methods. Not enforced in Java, but considered good OO programming practice. Code re use A fundamental principle of software engineering is basing software development of re usable technology. Reusing already tested/debugged objects leads to higher quality software. 18 of 59

19 BENEFITS OF OBJECT ORIENTATION Plug ability and debugging ease Because objects are self contained and independent, objects of the same type and same signature can be interchanged in an application very simply. If you discover an object that is more efficient than yours, you can replace your object with the more efficient object, provided the signature is the same. If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. EX: If a bolt breaks, you replace it, not the entire machine. 19 of 59

20 WHAT IS A CLASS? In the real world, you ll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object oriented terms, we say that your bicycle is an instance of the class of objects known as Bicycle. A class is the blueprint from which individual objects are created. 20 of 59

21 JAVA CODE FOR Bicycle CLASS class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changecadence(int newvalue) { cadence = newvalue; void changegear(int newvalue) { gear = newvalue; void speedup(int increment) { speed = speed + increment; void applybrakes(int decrement) { speed = speed - decrement; void printstates() { System.out.println("cad:"+cadence+" spd:"+speed+" gear:"+gear); 21 of 59

22 Bicycle CLASS DECLARATION class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changecadence(int newvalue) { cadence = newvalue; void changegear(int newvalue) { gear = newvalue; void speedup(int increment) { speed = speed + increment; void applybrakes(int decrement) { speed = speed - decrement; void printstates() { System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear); 22 of 59

23 Bicycle CLASS FIELDS: STATE class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changecadence(int newvalue) { cadence = newvalue; void changegear(int newvalue) { gear = newvalue; void speedup(int increment) { speed = speed + increment; void applybrakes(int decrement) { speed = speed - decrement; void printstates() { System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear); 23 of 59

24 Bicycle CLASS METHODS: BEHAVIOR class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changecadence(int newvalue) { cadence = newvalue; void changegear(int newvalue) { gear = newvalue; void speedup(int increment) { speed = speed + increment; void applybrakes(int decrement) { speed = speed - decrement; void printstates() { System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear); 24 of 59

25 Bicycle DEMO CLASS APPLICATION THAT INTERACTS WITH THE Bicycle CLASS class BicycleDemo { public static void main(string[] args) { // Create two different Bicycle objects Bicycle bike1 = new Bicycle(); Bicycle bike2 = new Bicycle(); // Invoke methods on those objects bike1.changecadence(50); bike1.speedup(10); bike2.changecadence(50); 25 of 59

26 UML REPRESENTATION OF A CLASS Name of class Bicycle gear speed changegear speedup List of Fields List of Methods 26 of 59

27 UML CLASSES AND ASSOCIATION BicycleDemo has a reference to Bicycle (indicated by the arrow). Bicycle gear speed changegear speedup BicycleDemo main() Line of Association. Bicycle does NOT have a reference to BicycleDemo (indicated by the lack of an arrow). 27 of 59

28 UML SEQUENCE DIAGRAM EXAMPLE: OBJECTIVE: TO SHOW HOW BicyleDemo CREATES AND SENDS MESSAGES TO Bicycle OBJECTS. User BicycleDemo Bicycle: bike1 Bicycle: bike2 java BicycleDemo create create main() changecadence(50) speedup(10) changecadence(50) 28 of 59

29 UML NOTES Class diagram Shows a static view of the program (system); i.e., it describes what classes are in the system and how they are related (association) Abstracted view of system Need to identify the objective for showing a class diagram Not all classes or components of classes need to be shown Show only the items which are needed to get your point (objective) across. Sequence diagram 29 of 59

30 UML NOTES: CLASS DIAGRAM Shows a static view of the program (system) It describes what classes are in the system and how they are related (association). Abstracted view of system Need to identify the objective for showing a class diagram Not all classes or components of classes need to be shown Show only the items which are needed to get your point (objective) across. 30 of 59

31 UML NOTES: SEQUENCE DIAGRAM Shows a dynamic view of the program (system) It describes the interaction between items in the system Items can be users, classes, objects, etc. Abstracted view of system Need to identify the objective for showing a sequence diagram Not all items in the system need to be shown Show only the items which are needed to get your point (objective) across. 31 of 59

32 WHAT IS INHERITANCE? Consider the blueprints (classes) of different types of bicycles. Examples: Tandem, Road, and Moumtain bikes The objects of these different types have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different Tandem bicycles have two seats and two sets of handlebars Road bikes have drop handlebars Mountain bikes have an additional chain ring: for lower gear ratio. It would be redundant to duplicate the code to describe the common fields and common behavior of these different types of bicycles. 32 of 59

33 WHAT IS INHERITANCE? Object oriented programming allows classes to inherit commonly used state and behavior from other classes. For example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. 33 of 59

34 UML REPRESENTATION OF INHERITANCE Superclass Bicycle gear changegear Closed, non filled, solid line triangle points to the superclass MountianBike chainring changechainring RoadBike handlebarpos changehandlebarpos TandemBike seat Subclass Subclass Subclass 34 of 59

35 INHERITANCE SYNTAX At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from: class MountainBike extends Bicycle { // New fields and new methods that make // a mountain bike different than a // Bicycle would go here. This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make MountainBike unique. 35 of 59

36 INHERITANCE EXAMPLE class MountainBike extends Bicycle { int seatheight; public void setheight(int newvalue) { seatheight = newvalue; public int getheight() { return seatheight; MountainBike inherits all the fields and methods of Bicycle and adds the field seatheight and methods to get and set it. 36 of 59

37 INHERITANCE RULES Java programming language specific rules Each class is allowed to have a maximum of one direct superclass. To minimize complexity Each superclass has the potential for an unlimited number of subclasses. Good Object Oriented practice rules Ensure each subclass obeys the 1. ISA rule 2. Distinctiveness rule 3. Rule that all inherited features make sense in each subclass. 37 of 59

38 INHERITANCE RULES: ISA RULE Ensure each subclass obeys the ISA rule A chequing account is an account. A village is a municipality. A mountain bike is a bike. Should Province be a subclass of Country? No, a Province is not a Country. Modeling a Province as a Country violates the ISA rule. Modeling a Province as Country would artificially introduce complexity into the source code, making the source code more difficult to understand, maintain, and use. 38 of 59

39 INHERITANCE RULES: DISTINCTIVENESS RULE A subclass must retain its distinctiveness throughout its life. Consider a bike with training wheels, for teaching kids to ride. You might consider creating a class called TrainingBicycle, and making this a subclass of Bicycle. However, a training wheel bicycle will not be a training bike once the training wheels are removed. Therefore, TrainingBicycle is not a subclass of Bicycle. Modeling a TrainingBicycle as a Bicycle would artificially introduce complexity into the source code, making the source code more difficult to understand, maintain, and use. Actually, TrainingBicycle should not even be a class. It s better to have a field that indicates if a Bicycle has training wheels. 39 of 59

40 INHERITANCE RULES: MSFMS Make Sure that each Feature of a superclass Makes Sense in each subclass. Each subclass inherits the features of a superclass. Modeling a class as a subclass of some superclass with one or more features that do not make sense in the subclass would artificially introduce complexity into the source code, making the source code more difficult to understand, maintain, and use. 40 of 59

41 ADVANTAGES OF INHERITANCE Only one copy of the common features of a set of subclasses is coded: they are coded only in the superclass No duplication of code Avoids errors of copying the features to each of the subclasses More flexible for change, for examples: Replacing a more efficient method in the superclass means each of the subclasses will also have the benefit of the more efficient method, since it is inherited Adding/removing fields to/from the superclass affects all classes underneath the superclass 41 of 59

42 WHAT IS AN INTERFACE? Objects define their interaction with the outside world through the methods that they expose. Methods form the object s interface with the outside world. For example, The buttons on the front of your television set are the interface between you and the electrical, electronic, and digital circuits on the other side of its plastic casing. You press the power button to turn the television on and off. 42 of 59

43 MOTIVATION FOR HAVING AN INTERFACE 1. The main reason for having an interface is CONVENIENCE. Suppose you have written several re usable classes that offer a main point of functionality, which is implemented by a set of primary methods, but that the classes had other methods which are either supporting methods or for another purpose You want to give other developers easier access to the primary methods of the main point of functionality. It would be good if: Developers did not have to search through your set of classes and determine what are the desired primary methods There was a mechanism to publish (make known) the primary methods in a single container (Interface) This would be more convenient. 43 of 59

44 MOTIVATION FOR HAVING AN INTERFACE 2. Easier to replace objects in the system The required methods an object needs to provide to a system is formalized and published in the interface The interface or set of interfaces could be the only connection the object has with the other objects in the system Therefore, to replace an object with a new one, the new object need only implement the required interface. 44 of 59

45 JAVA INTERFACE Java provides such a mechanism, called an interface. An interface is a formal specification of a set of related methods that a class (or a group of classes) provides and implements. In Java, an interface is a group of related methods with empty bodies. A class (or group of classes) provides the implementation of the methods specified in the interface. 45 of 59

46 INTERFACE: BICYCLE EXAMPLE To specify (or advertise) the methods that the Bicycle hierarchy provides to effect speed (i.e., a main point of functionality), consider creating an interface called BicycleSpeed. interface BicycleSpeed { void setcadence(int newvalue); void setgear(int newvalue); void speedup(int increment); Now, a developer need not search the Bicycle hierarchy for the methods that effect speed: that information is contained in the BicycleSpeed interface. Note: there is no body for each method in the interface, as required. Methods with no bodies are called abstract methods. 46 of 59

47 INTERFACE: BICYCLE EXAMPLE To implement this interface, use the implements keyword in the class declaration. class Bicycle implements BicycleSpeed { void setcadence(int newvalue){ //code for changing the cadence. void setgear(int newvalue){ // code for changing the gear. //Other methods interface BicycleSpeed { void setcadence(int newvalue); void setgear(int newvalue); 47 of 59

48 UML REPRESENTATION OF INTERFACE Dashed line connects the class with the interface. Interface «interface» BicycleSpeed setcadence setgear This class hierarchy implements the interface BicycleSpeed. Bicycle setcadence setgear Closed, non filled, dashed line triangle points to the interface MountainBike RoadBike TandemBike chainring changechainring handlebarpos changehandlebarpos seat 48 of 59

49 SIMPLE APPLICATION PURPOSE: TO CHANGE SPEED OF A MOUNTAIN BIKE BicycleDemo «interface» BicycleSpeed setcadence setgear User of the Bicycle hierarchy for the sole purpose of changing speed of a mountain bike. TandemBike Bicycle setcadence setgear MountainBike Assume Bicycle Hierarch is very Complex 49 of 59

50 Bicycle CLASS IN FILE Bicycle.java public class Bicycle implements BicycleSpeed { // the Bicycle class has three fields public int cadence; public int gear; public int speed; // the Bicycle class has one constructor public Bicycle(int startcadence, int startspeed, int startgear) { gear = startgear; cadence = startcadence; speed = startspeed; 50 of 59

51 Bicycle CLASS (CONTINUED) // the Bicycle class has four methods public void setcadence(int newvalue) { cadence = newvalue; public void setgear(int newvalue) { gear = newvalue; public void applybrake(int decrement) { speed -= decrement; public void speedup(int increment) { speed += increment; 51 of 59

52 MountainBike CLASS IN FILE BountainBike.java public class MountainBike extends Bicycle { // the MountainBike subclass adds one field public int seatheight; // the MountainBike subclass has one constructor public MountainBike(int startheight, int startcadence, int startspeed, int startgear) { super(startcadence, startspeed, startgear); seatheight = startheight; // the MountainBike subclass adds one method public void setheight(int newvalue) { seatheight = newvalue; 52 of 59

53 BicycleSpeed INTERFACE IN FILE BicycleSpeed.java interface BicycleSpeed { void setcadence(int newvalue); void setgear(int newvalue); void speedup(int increment); 53 of 59

54 BicycleDemo CLASS IN FILE BicycleDemo.java public class BicycleDemo{ public static void main(string[] args) { MountainBike mymountainbike = new MountainBike(1, 2, 3, 4); BicycleSpeed speedofmymountainbike; speedofmymountainbike = mymountainbike; BicycleDemo «interface» BicycleSpeed setcadence setgear speedofmymountainbike.setcadence(5); Bicycle speedofmymountainbike.setgear(6); MountainBike System.out.printf("gear is %d%n", mymountainbike.gear); System.out.printf("cadence is %d%n", mymountainbike.cadence); 54 of 59

55 JAVA INTERFACE RULES Each class is allowed to implement any number of interfaces. Each method specified in an interface cannot have any implementation. Each method in an interface must have an empty body. Each method specified in an interface must be implemented by some class in the source code. If a class claims to implement an interface, all methods defined by that interface must appear in the class s source code. Otherwise the class will not compile successfully. 55 of 59

56 WHAT IS A PACKAGE? A package is a container in which related classes and interfaces are grouped together. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. For large programs which are composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages. 56 of 59

57 JAVA S PACKAGES: API The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the Application Programming Interface (API). The packages within the API represent the tasks most commonly associated with general purpose programming. 57 of 59

58 EXAMPLES OF JAVA PACKAGES java.lang The String, Integer, Double and other related classes are contained within the java.lang package. For example, the Integer class contains state and behavior for common integer tasks, such as Converting a string to an Integer object. java.io a File object allows a programmer to easily create, delete, inspect, or modify a file on the file system. The File and other related classes are contained within the java.io package. 58 of 59

59 EXAMPLES OF JAVA PACKAGES java.net a Socket object allows for the creation and use of network sockets. The Socket and other related classes are contained within the jave.net package. java.awt various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. The GUI related classes are contained within the java.awt package. There are many other packages and literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your particular application, rather than the infrastructure required to make it work. 59 of 59

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson ) Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson ) Dongwon Jeong djeong@kunsan.ac.kr; http://ist.kunsan.ac.kr/ Information Sciences and Technology

More information

Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on:

Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on: 1 Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on: [1] Timothy A. Budd, Oregon State University, Corvallis, Oregon, [Available] ClickMe, September 2001. 2 What

More information

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem UNIT-1 ECS-503 Object Oriented Techniques Part-1: Object-Oriented Programming Concepts What Is an Object? Objects are key to understanding object-oriented technology. Look around right now and you'll find

More information

Universiti Malaysia Perlis

Universiti Malaysia Perlis Universiti Malaysia Perlis EKT420: SOFTWRE ENGINEERING Lab 5: Inheritance and Interfaces Pusat Pengajian Kejuruteraan Komputer Dan Perhubungan Universiti Malaysia Perlis 1 INHERITANCE Object-oriented programming

More information

Computer Science 210: Data Structures

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

More information

Inheritance, part 2: Subclassing. COMP 401, Spring 2015 Lecture 8 2/3/2015

Inheritance, part 2: Subclassing. COMP 401, Spring 2015 Lecture 8 2/3/2015 Inheritance, part 2: Subclassing COMP 401, Spring 2015 Lecture 8 2/3/2015 Motivating Example lec8.ex1.v1 Suppose we re writing a university management system. Interfaces: Person get first and last name

More information

Java Programming Tutorial 1

Java Programming Tutorial 1 Java Programming Tutorial 1 Every programming language has two defining characteristics: Syntax Semantics Programming Writing code with good style also provides the following benefits: It improves the

More information

Outline. Object-Oriented Design Principles. Object-Oriented Design Goals. What a Subclass Inherits from Its Superclass?

Outline. Object-Oriented Design Principles. Object-Oriented Design Goals. What a Subclass Inherits from Its Superclass? COMP9024: Data Structures and Algorithms Week One: Java Programming Language (II) Hui Wu Session 1, 2014 http://www.cse.unsw.edu.au/~cs9024 Outline Inheritance and Polymorphism Interfaces and Abstract

More information

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials Introduction to Android Saturday Yanqiao ZHU Google Camp School of Software Engineering, Tongji University In courtesy of The Java Tutorials Getting Started Introduction to Java The Java Programming Language

More information

Inheritance. The Java Platform Class Hierarchy

Inheritance. The Java Platform Class Hierarchy Inheritance In the preceding lessons, you have seen inheritance mentioned several times. In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Object Oriented Programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 23, 2010 G. Lipari (Scuola Superiore

More information

Data Types. Lecture2: Java Basics. Wrapper Class. Primitive data types. Bohyung Han CSE, POSTECH

Data Types. Lecture2: Java Basics. Wrapper Class. Primitive data types. Bohyung Han CSE, POSTECH Data Types Primitive data types (2015F) Lecture2: Java Basics Bohyung Han CSE, POSTECH bhhan@postech.ac.kr Type Bits Minimum Value Maximum Value byte 8 128 127 short 16 32768 32767 int 32 2,147,483,648

More information

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

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

More information

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

Tony Valderrama, SIPB IAP 2009

Tony Valderrama, SIPB IAP 2009 Review Summary of topics from Tuesday Corrections Brief example of interactive application Static imports Compiling and executing from command line Class members More details about compiler/runtime environment

More information

Lesson: Classes and Objects

Lesson: Classes and Objects Lesson: Classes and Objects With the knowledge you now have of the basics of the Java programming language, you can learn to write your own classes. In this lesson, you will find information about defining

More information

Object oriented programming Concepts

Object oriented programming Concepts Object oriented programming Concepts Naresh Proddaturi 09/10/2012 Naresh Proddaturi 1 Problems with Procedural language Data is accessible to all functions It views a program as a series of steps to be

More information

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

NATIONAL DIPLOMA IN COMPUTER TECHNOLOGY

NATIONAL DIPLOMA IN COMPUTER TECHNOLOGY UNESCO-NIGERIA TECHNICAL & VOCATIONAL EDUCATION REVITALISATION PROJECT-PHASE II NATIONAL DIPLOMA IN COMPUTER TECHNOLOGY (COM213) YEAR 2-SEMESTER 1 PRACTICAL Version 1: December 2008 1 Table of Contents

More information

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects,

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects, Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects, Classes, Class Diagrams Values and Attributes Operations

More information

CS260 Intro to Java & Android 03.Java Language Basics

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

More information

Object-oriented perspective

Object-oriented perspective Starting Reader #2 Object-oriented perspective Operating system = computer interface Shell/libraries/system calls = OS interface Will return to OS topics in upcoming lectures. Now: OO intro. Objects l

More information

Chapter 2: Java OOP I

Chapter 2: Java OOP I Chapter 2: Java OOP I Yang Wang wyang AT njnet.edu.cn Outline OO Concepts Class and Objects Package Field Method Construct and Initialization Access Control OO Concepts Object Oriented Methods Object An

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

Object-oriented. Service Innovation

Object-oriented. Service Innovation Object-oriented Service Innovation Overall Concepts Real World OO World Collaboration Delegation using services at SAP (service access point) 사과 3 개 Abstract Interacting, Collaborating Objects by Delegating

More information

CSE 21 Intro to Computing II. Inheritance

CSE 21 Intro to Computing II. Inheritance CSE 21 Intro to Computing II Inheritance 1 Administrative Business Lab11 (this week) is due on November 27 th extension Extra lab section on Tuesday November 20 th from 3-6pm (SE138) No lab November 20/23

More information

IT2301 JAVA PROGRAMMING

IT2301 JAVA PROGRAMMING IT2301 JAVA PROGRAMMING 3 0 0 3 AIM: To understand the concepts of object-oriented, event driven, and concurrent programming paradigms and develop skills in using these paradigms using Java. UNIT I 9 Object

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

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

Object-Oriented Programming Paradigm

Object-Oriented Programming Paradigm Object-Oriented Programming Paradigm Sample Courseware Object-Oriented Programming Paradigm Object-oriented programming approach allows programmers to write computer programs by representing elements of

More information

Lecture 2: Java & Javadoc

Lecture 2: Java & Javadoc Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block

More information

The class definition is not a program by itself. It can be used by other programs in order to create objects and use them.

The class definition is not a program by itself. It can be used by other programs in order to create objects and use them. Data Classes and Object-Oriented Programming Data classes can be motivated by the need to create data structures that have grouped together a number of variables of simpler type (ints, Strings, arrays)

More information

PROGRAMMING LANGUAGE 2

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

More information

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

Software Architecture (Lesson 2) Object-Oriented Paradigm (1) Software Architecture (Lesson 2) Object-Oriented Paradigm (1) Table of Contents Introduction... 2 1.1 Basic Concepts... 2 1.1.1 Objects... 2 1.1.2 Messages... 3 1.1.3 Encapsulation... 4 1.1.4 Classes...

More information

Exercise: Singleton 1

Exercise: Singleton 1 Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance

More information

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal

Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Define and discuss abstract classes Define and discuss abstract methods Introduce polymorphism Much of the information

More information

What is the output of the following code segment:

What is the output of the following code segment: Question 1: (12 Marks) a- what is the output made by the following portion of code int i =1, V=0, W=0; while (i

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized around the notion of procedures Procedural abstraction

More information

Design Patterns. Design Patterns 1. Outline. Design Patterns. Bicycles Simulator 10/26/2011. Commonly recurring patterns of OO design

Design Patterns. Design Patterns 1. Outline. Design Patterns. Bicycles Simulator 10/26/2011. Commonly recurring patterns of OO design G52APR Applications Programming Design Patterns 1 Design Patterns What is design patterns? The design patterns are languageindependent strategies for solving common object-oriented design problems. Jiawei

More information

CITS2210. Object-Oriented Programming. Topic 1. Introduction and Fundamentals: Thinking Object-Oriented

CITS2210. Object-Oriented Programming. Topic 1. Introduction and Fundamentals: Thinking Object-Oriented CITS2210 Object-Oriented Programming Topic 1. Introduction and Fundamentals: Thinking Object-Oriented Summary: This topic considers the fundamental concepts behind object orientation, and why they are

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

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

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

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Ray John Pamillo 1/27/2016 1 Nokia Solutions and Networks 2014 Outline: Brief History of OOP Why use OOP? OOP vs Procedural Programming What is OOP? Objects and Classes 4 Pillars

More information

Classes, subclasses, subtyping

Classes, subclasses, subtyping 1 CSCE 314: Programming Languages Dr. Flemming Andersen Classes, subclasses, subtyping 2 3 Let me try to explain to you, what to my taste is characteristic for all intelligent thinking. It is, that one

More information

Subclasses, Superclasses, and Inheritance

Subclasses, Superclasses, and Inheritance Subclasses, Superclasses, and Inheritance To recap what you've seen before, classes can be derived from other classes. The derived class (the class that is derived from another class) is called a subclass.

More information

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

Object-Oriented Modeling Using UML. CS151 Chris Pollett Aug. 29, 2005.

Object-Oriented Modeling Using UML. CS151 Chris Pollett Aug. 29, 2005. Object-Oriented Modeling Using UML CS151 Chris Pollett Aug. 29, 2005. Outline Objects and Classes Modeling Relationships and Structures Some Terms and Concepts Objects and classes are fundamental to OO

More information

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

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

More information

Structured Programming

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

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

CHAPTER 5 GENERAL OOP CONCEPTS

CHAPTER 5 GENERAL OOP CONCEPTS CHAPTER 5 GENERAL OOP CONCEPTS EVOLUTION OF SOFTWARE A PROGRAMMING LANGUAGE SHOULD SERVE 2 RELATED PURPOSES : 1. It should provide a vehicle for programmer to specify actions to be executed. 2. It should

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

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

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

More information

C++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming

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

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

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

More information

CS260 Intro to Java & Android 02.Java Technology

CS260 Intro to Java & Android 02.Java Technology CS260 Intro to Java & Android 02.Java Technology CS260 - Intro to Java & Android 1 Getting Started: http://docs.oracle.com/javase/tutorial/getstarted/index.html Java Technology is: (a) a programming language

More information

UML - Class Diagrams

UML - Class Diagrams UML - Class Diagrams What is UML Diagram? Unified Modeling Language (UML) Standardized general-purpose modeling language in the field of object-oriented software engineering. The standard is managed, and

More information

Basics of Object Oriented Programming. Visit for more.

Basics of Object Oriented Programming. Visit   for more. Chapter 4: Basics of Object Oriented Programming Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,

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

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

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

Learning the Java Language. 2.1 Object-Oriented Programming

Learning the Java Language. 2.1 Object-Oriented Programming Learning the Java Language 2.1 Object-Oriented Programming What is an Object? Real world is composed by different kind of objects: buildings, men, women, dogs, cars, etc. Each object has its own states

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

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

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

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

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

More information

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

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

Software Development. Modular Design and Algorithm Analysis

Software Development. Modular Design and Algorithm Analysis Software Development Modular Design and Algorithm Analysis Data Encapsulation Encapsulation is the packing of data and functions into a single component. The features of encapsulation are supported using

More information

Object Oriented Programming (Java and Visual Basic)

Object Oriented Programming (Java and Visual Basic) Biyani's Think Tank Concept based notes Object Oriented Programming (Java and Visual Basic) (BCA Part-II) Shipra Rastogi Revised By: Kritika Saxena Deptt. of Information Technology Biyani Girls College,

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

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

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

More information

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

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

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

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming) C++ Programming: Introduction to C++ and OOP (Object Oriented Programming) 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Brief introduction to C++ OOP vs. Procedural

More information

Example: Fibonacci Numbers

Example: Fibonacci Numbers Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers

More information

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

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

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas What is this class about? While this class is called Design Patterns, there are many other items of critical

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Inheritance A form of software reuse in which a new class is created by absorbing an existing class s members and enriching them with

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

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

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

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

More information

Inheritance (Part 2) Notes Chapter 6

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

More information

Introduction to Object- Oriented Programming

Introduction to Object- Oriented Programming Introduction to Object- Oriented Programming Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us

More information

Another IS-A Relationship

Another IS-A Relationship Another IS-A Relationship Not all classes share a vertical relationship. Instead, some are supposed to perform the specific methods without a vertical relationship. Consider the class Bird inherited from

More information

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University (5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming

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

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

Introduction to Design Patterns Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can

More information

Inheritance CSC 123 Fall 2018 Howard Rosenthal

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

More information

C++ Classes & Object Oriented Programming

C++ Classes & Object Oriented Programming C++ Classes & Object Oriented Programming What is it? Object Oriented Programming 1 Object Oriented Programming One of the first applications of modern computing was modeling and simulation. Scientists

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

Friend Functions, Inheritance

Friend Functions, Inheritance Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by

More information