Object-Oriented Programming Paradigm

Size: px
Start display at page:

Download "Object-Oriented Programming Paradigm"

Transcription

1 Object-Oriented Programming Paradigm Sample Courseware Object-Oriented Programming Paradigm Object-oriented programming approach allows programmers to write computer programs by representing elements of a real-world problem in the form of so-called objects. In object-oriented programs objects are used to represent both: behaviors of realworld objects as well as their characteristics. All work in an object-oriented program is done by objects, which communicate with each other by sending messages, i.e., by requesting other object to perform certain operations. 1 Introduction & Basic Concepts This approach to writing computer programs was a huge step forward in comparison to procedural programming approach. In procedural programming we try to model a real-world problem as procedures and sequences of their execution. Thinking and programming in terms of objects is much more natural than thinking and programming in terms of procedures. The basic concepts of object-oriented programming are: 1.1 Basic Concepts: Objects Real-world objects are distinguished through: Characteristics or state Behavior. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (1 of 28) [10/16/2002 4:14:13 PM]

2 For example, dogs have state (name, color, breed, hungry) and behavior (barking, fetching, and wagging tail). Planes have state (current speed, position of rudders, current altitude) and behavior (accelerating, slowing down, changing a rudder position). In object-oriented programs we represent real-world objects by means of software objects also known as abstract objects or simply objects. These objects are modeled after real-world objects in that they too have state and behavior: Software object maintains its state in one or more variables. A variable is an item of data named by an identifier. Software object implements its behavior with methods. A method is a function (subroutine) associated with an object. Thus, we can define an object as a piece of software that combines variables and related methods. For example, we might represent a car as an object that has variables indicating its current state: its current gear is the 4th gear; its current speed is 100 km/h; its color is file:///e /LV_CD/wbtmaster/main_library/swp2.htm (2 of 28) [10/16/2002 4:14:13 PM]

3 grey, etc. We call these variables formally instance variables, because they contain state of a particular object. A particular object in object-oriented terminology is called an instance. In addition to instance variables the car object has methods to change its current state: to brake, accelerate or change the current gear. Again, these methods are formally known as instance methods, because we use them to change the current state of a particular object, i.e., of a particular car instance. 1.2 Basic Concepts: Messages Single objects are not very useful. Instead, an object usually appears as just one object of an object-oriented program that contains many objects. In such program all work is done by interaction between these objects. For instance, the car object from the previous example is not very useful if it is alone in an object-oriented program. However, if we have another object representing a person, this person object may interact with the car object by telling it to change the current gear, to speed up, etc. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (3 of 28) [10/16/2002 4:14:13 PM]

4 Speaking more formally, an object-oriented program consists of a number of objects, which communicate with each other by sending so-called messages. Thus, if one object wants another object to do something then it sends a message to the second object. Practically, sending message is equal to calling an instance method of another object. Sometimes, the object, which receives a message, needs to have more information in order to properly execute its method. For instance, if the car object has to change its gear it has to know which is the desired gear. Such additional information is attached to the message and called message parameters Summarizing, a message is comprised out of the following components: The object that receives the message (Target) The name of the method to execute (Selector) Additional parameters needed to execute the method (Parameters) Optionally, an object which is returned as a result of the message evaluation (Responce) file:///e /LV_CD/wbtmaster/main_library/swp2.htm (4 of 28) [10/16/2002 4:14:13 PM]

5 1.3 Basic Concepts: Encapsulation The above discussion showed that the object's variables make up the current state of an object. The only way in which we can alter the state of an object is by sending messages to it, i.e., by calling its methods. Thus, the current state of an object is hidden from other objects. It is however, surrounded by its methods, which provide an interface between this object and other objects. Packaging an object's variables within the protective custody of its methods is called a data encapsulation. The concept of data encapsulation is one of the most important concepts of objectoriented with a number of advantages. Most important benefits for programmers coming from this idea are: Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Also, an object can be file:///e /LV_CD/wbtmaster/main_library/swp2.htm (5 of 28) [10/16/2002 4:14:13 PM]

6 easily passed around in the system. You can give your car to someone else, and it will still work. Information hiding: An object has a public interface that other objects can use to communicate with it. The object can maintain private information and methods that can be changed at any time without affecting the other objects that depend on it. You don't need to understand the gear mechanism on your car to use it. 1.4 Basic Concepts: Classes In the real world there are objects that are of the same kind. Some of these objects have things in common with other objects. For instance, all cars have some state (gear, speed, etc.) and behavior (change gear, accelerate, etc.) in common. However, the state of each car is independent and can be different from other cars. In object-oriented programming we try to catch things that objects have in common by defining classes of objects. A class is a prototype that defines variables and methods that are common to all objects of the same kind. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (6 of 28) [10/16/2002 4:14:13 PM]

7 After the car class has been created, we can create any number of car objects from the class. This process is known as intanciation of the class. When we create an instance of a class, the system allocates enough memory for the object and all its instance variables. Each instance gets its own copy of the entire instance variables defined in the class. 1.5 Basic Concepts: Composition file:///e /LV_CD/wbtmaster/main_library/swp2.htm (7 of 28) [10/16/2002 4:14:13 PM]

8 Some real-world objects can be quite complex. Usually, such complex objects are built by composing a possible large number of simpler objects. Object-oriented programming allows programmers to follow the same composition (aggregation) approach. It is possible to create more complex software objects by combining already existing objects into a new one. A class defining such a complex or composite object declares its instance variables to be other objects. An object's current state is composition of current states of its instance variables. Thus, an employee is identified by a current state of his/her bank account and car. Behavior of a particular object is a composition of behaviour of its parts. For instance, transfering some amount of money as a person's salary would cause transfering this money to his bank account via the method "transaction". file:///e /LV_CD/wbtmaster/main_library/swp2.htm (8 of 28) [10/16/2002 4:14:13 PM]

9 1.6 Basic Concepts: Inheritance Object-oriented programming paradigm allows programmers to define more special cases of a class through the concept of inheritance (specialization). The special case of a class is called subclass, and the original class is called superclass. For example, the car class from our example would be superclass with the following subclasses: sport car class, passenger car class, truck class, and so on. Each subclass inherits: State (in the form of variable declarations) from the superclass. Sport cars, trucks and passenger cars share some states: gear, speed, and the like. Methods from the superclass. Sport cars, trucks and passenger cars share some behaviors: braking and changing speed, for example. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (9 of 28) [10/16/2002 4:14:13 PM]

10 However, subclasses are not limited to the state and behaviors predefined by superclass. Defining Subclasses, programmers are allowed: add variables and methods to the ones they inherit from the superclass override inherited variables and methods, i.e. to provide specialized implementations. supress inherited variables and methods, is they are not needed. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (10 of 28) [10/16/2002 4:14:13 PM]

11 Finally, programmers are not limited to just one layer of inheritance. The inheritance tree, or class hierarchy, can be as deep as needed. Methods and variables are inherited down through the levels. In general, the farther down in the hierarchy a class appears, the more specialized its behavior. Similar to the composition principle the inheritance principle provides for the reuse of software components. However, with inheritance we reuse the interface (and consequently the implementation of methods) of a class we are subclassing. The subclass has the same interface as the superclass, thus its instances can receive the same messages as its superclass. 1.7 Basic Concepts: Abstract Classes and Interfaces Often, programmers implement superclasses called abstract classes just to define "generic" behaviors. An abstract superclass defines and may partially implement a behavior, but much of the class is undefined and unimplemented. Other programmers fill in the details with specialized subclasses. Abstract classes declare one or more methods as abstract methods. If a prohrammer inherits file:///e /LV_CD/wbtmaster/main_library/swp2.htm (11 of 28) [10/16/2002 4:14:13 PM]

12 property from an abstract superclass, the programmer has to implement all abstract methods or the subclass is considered to be abstract as well. It is not possible to create instances of abstract classes. Abstract classes just provide an interface and functionality that can be reused. Another similar concept is called an interface. An interface may be seen as an abstract class with all methods declared as abstract. Moreover, an interface explicitly forbid any method definition, allowing programmers to declare just a number of empty methods. 1.8 Basic Concepts: Polymorphism Polymorphism and Dynamic Binding are two closely related concepts that essentially provide well-known flexibilty of Object-Oriented systems. Dynamic Bindig of messages to methods means that a message selector does not define a code to be evaluated. The code is identified dynamically when an object receives the message. Dynamic Bindig of messages to methods can be explained with the following example. Suppose we have two classes "Programmer" and "Manager" with identical interface. Suppose also that method "salary" has been defined differently for these classes. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (12 of 28) [10/16/2002 4:14:13 PM]

13 The message "Nick.salary()" does not define a particular code since the object may belong to different classes. The code can be identified only dynamically when the object receives the message. Generally, Polymorphism is perceived as an independence of a code definition and types to which belong variables referred to. Polymorphism can be illustrated with the following example. Suppose we have two classes "Programmer" and "Manager" with identical interface. Since, inastances of these classes support identical set of messages. A method code defined for a third class "Car" may refer to a polymorhic variable "Owner". The variable "Owner" may have any instance of these two classes as a value. Moreover, the variable may even refer to any other instance having identical public interface (for example, "Student", "Person", etc.) 2 Defining Classes file:///e /LV_CD/wbtmaster/main_library/swp2.htm (13 of 28) [10/16/2002 4:14:13 PM]

14 A class definition statement defines the following components: class name and type number of instance variables number of public methods to manipulate the instance variables number of so-called constructors that are used to initialize an instance For example, public class Employee // // class definition // The code declares a public class "Employee". Public class means that other classes may reuse this class either for inheritance or for composition. 2.1 Defining Private Memory Defining Instance variables in Object-Oriented Programming is knowm as binding variables to domains. In other words, a particular variable is bound to an existing class meaning that the variable may hold an instance of this class as a value. For example, public class Employee private String Name; private BankAccount B_Account; the code defines two variables (Name and B_Account); variable Name holds an instance of the class "String" as a value variable B_Account holds an instance of the class "BankAccount" as a value file:///e /LV_CD/wbtmaster/main_library/swp2.htm (14 of 28) [10/16/2002 4:14:13 PM]

15 The class "String" is called a Standard Library Class. Programmers do not need to define standard classes rather they should learn what public interface is supported by instances of these classes. The class "BankAccount" is called an user-defined class. Programmers have to define such classes or reuse classes defined by other programmers. When an instance variable is declared, it is normally initialized to a particular value. This initial value is automatically assigned to the variable when a new instance of the class is created. For example, public class Employee private String Name = 'an employee'; private BankAccount B_Account; If an initial value is not provided, an instance variable obtains a default value. Object constructors (i.e. messages "New") may be also used to initialize instance variables. For example, public class Employee private String Name = 'an employee'; private BankAccount B_Account = new BankAccount('',0); Here, we use the constructor ("new BankAccount('',0)") to initialize a new bank account whenever a new instance of "Employee" is created. 2.2 Defining Methods Recollect, methods are invoked by messages, a message is comprised out of the three following components: file:///e /LV_CD/wbtmaster/main_library/swp2.htm (15 of 28) [10/16/2002 4:14:13 PM]

16 The object that receives the message (Target) The name of the method to execute (Selector) Additional parameters needed to execute the method (Parameters) Optionally, an object which is returned as a result of the message evaluation (Responce) Thus a method definition consists of two parts: message template that defines a structure of messages to be used to invoke the method; message body that defines an actual algoritm to be performed by the method For example, public class Employee // Variables private String Name = 'an employee'; private BankAccount B_Account = new BankAccount('',0); // Methods public String salary(numeric Sum) /* Message Template */ // method body The message template above defines all the message components and properties: selector is "salary", the method is public, i.e. other objects may use the selector. parameter is an instance of class "numeric" - primitive type, this instance may be reused in the method body as variable "Sum" responce is an instance of class "String" - primitive type file:///e /LV_CD/wbtmaster/main_library/swp2.htm (16 of 28) [10/16/2002 4:14:13 PM]

17 Method body is defined as a number of messages sent to other objects. Of course, identity of such objects receving messages, must be known inside the body. In a simlest case, method body sends messages to private variables. For example, suppose that the class "BankAccount" has a public method called "transaction". Transacrion has just one parameter - an amount of money to be transfered to the bank account (may be a negative value). Suppose also that the method returns a Boolean value as a responce. public class Employee // Variables private String Name = 'an employee'; private BankAccount B_Account = new BankAccount('',0); // Methods public String salary(numeric Sum) /* Message Template */ if (B_Account.transaction(Sum))return("Thanks"); else return("sorry, I have not got the money!"); Objects received by a method as parameters may be also used to send messages and gather responces. For example, suppose a firm sends a message salary with two parameters: an amount of money and a bank account from which the money should be transfered. public class Employee // Variables private String Name = 'an employee'; private BankAccount B_Account = new BankAccount('',0); // Methods public String salary( numeric Sum, BankAccount Firm_Account) if (Firm_Account.transaction(-Sum) && B_Account.transaction(Sum))return("Thanks"); file:///e /LV_CD/wbtmaster/main_library/swp2.htm (17 of 28) [10/16/2002 4:14:13 PM]

18 else return("sorry, the firm seems to be a bankrupt!"); Just to complete our preliminary discussion on the method definition facilities, let us mention a rather important feature: polymorphism or dynamical binding allows us to omit definition of concrete classes to which message parameters should belong; public class Employee // Variables private String Name = 'an employee'; private BankAccount B_Account = new BankAccount('',0); // Methods public Object salary( Object Sum, Object Firm_Account) if (Firm_Account.transaction(Sum.negative()) && B_Account.transaction(Sum))return("Thanks"); else return("sorry, the firm seems to be a bankrupt!"); The above definition is much more flexible, it requires: an object used as a first parameter, supports a method "negative()" an object used as a secont parameter, supports a method "transaction()" public class Employee... public Object salary( Object Sum, Object Firm_Account) if (Firm_Account.transaction(Sum.negative()) && B_Account.transaction(Sum))return("Thanks"); else return("sorry, the firm seems to be a bankrupt!"); file:///e /LV_CD/wbtmaster/main_library/swp2.htm (18 of 28) [10/16/2002 4:14:13 PM]

19 No we can define such classes as "Shilling", "Euro", "Rubles", etc. and use instances of these classes as parameters of the message. Similarly, different types of bank accounts ("Anonymous Account", "Saving Account", "Student Account", etc.) may be defined as special classes. Instances of these classes may be used as the second parameter providing that all the classes define a method called "transaction": 3 Objects Generally, Object-oriented programming approach may be seen as manipulation with multiple objects. Programmers create new objects, send messages to existing objects and collect responces in a form of objects to which other messages may be sent, etc Creating Objects Any object is created by sending a message "New" to a class. A class defines common property (i.e. variables and methods) of all instances (i.e. objects). BankAccount myaccount = new BankAccount (12/73, 0); String myname = new String ('Nick'); Employee measemployee = new Employee (myname, myaccount); Each of these three statements consist of the three fundamental parts: Variable declaration - it associates a name to a newly created object, or to a place file:///e /LV_CD/wbtmaster/main_library/swp2.htm (19 of 28) [10/16/2002 4:14:13 PM]

20 holder for an object. Instantiation - the operator new creates a new object, i.e., it dynamically allocates memory space for it Initialization - the new operator is followed by a constructor, which initialize the newly created object. Variable Declaration does not create an object, it just declares a variable which will be used to refer to a particular instance of the class. BankAccount myaccount // Variable "myaccount" Declaration = new BankAccount (12/73, 0); String myname // Variable "myname" Declaration = new String ('Nick'); Employee measemployee // Variable "measemployee" Declaration = new Employee (myname, myaccount); Instantiation is carried out by means of the operator "new". The operator creates an instance (allocae memory for a new object) and sets the variable as a reference to the object. BankAccount myaccount = new // Variable "myaccount" contains reference to // a new instance of "BankAccount" BankAccount (12/73, 0); String myname = new // Variable "myname" contains reference to // a new instance of "String" String ('Nick'); Employee measemployee = new // Variable "measemployee" contains reference to file:///e /LV_CD/wbtmaster/main_library/swp2.htm (20 of 28) [10/16/2002 4:14:13 PM]

21 // a new instance of "Employee" Employee (myname, myaccount); To initialize objects each class definition provides a number of constructors, to provide initial values for instances of that class. For example, the class "String" requires just one initial value. BankAccount myaccount = new BankAccount (12/73, 0); // Variable "myaccount" contains reference to // a new instance of "BankAccount" // (private variables are created and set as "12/73, 0") String myname = new String ('Nick'); // Variable "myname" contains reference to // a new instance of "String" // (the String current value is "Nick") Employee measemployee = new Employee (myname, myaccount); // Variable "measemployee" contains reference to // a new instance of "Employee" // (private variables are created and set as references to previously created objects) Note, a partial definition of variables can be also used. BankAccount myaccount; // Variable "myaccount" just a place holder for // instances of "BankAccount" String myname = new Object; // Variable "myname" contains reference to // a new instance of "String" // (current value is not defined) Employee measemployee = new Employee (myname, myaccount); file:///e /LV_CD/wbtmaster/main_library/swp2.htm (21 of 28) [10/16/2002 4:14:13 PM]

22 // Variable "measemployee" contains reference to // a new instance of "Employee" // (private variables are created and set as references to previously created objects) 3.2 Sending Messages A message is sent to an object by means of the following construct: <Target>.<Selector> (<Parameters>); Example: BankAccount myaccount = new BankAccount (12/73, 0); String myname = new String ('Nick'); Employee measemployee = new Employee (myname, myaccount); measemployee.salary(1000); A message responce is an object in turn, and can evaluate messages by means of associated methods. <(<Target>.<Selector> (<Parameters>))>.<Selector> (<Parameters>); Example: The method "salary" replyes with an object. Suppose this object belongs to a class where a method "print" is defined; BankAccount myaccount = new BankAccount (12/73, 0); String myname = new String ('Nick'); Employee measemployee = new Employee (myname, myaccount); Object responcetosalary = measemployee.salary(1000); responcetosalary.print(); file:///e /LV_CD/wbtmaster/main_library/swp2.htm (22 of 28) [10/16/2002 4:14:13 PM]

23 or coded in a more compact form: BankAccount myaccount = new BankAccount (12/73, 0); String myname = new String ('Nick'); Employee measemployee = new Employee (myname, myaccount); (measemployee.salary(1000)).print(); 3.3 Object Life Cicle To support efficiency, lifetime of objects can be statically determined by a context (i.e. procedure) in which the object is created. Such approach provides a maximum run-time performance, at the cost of flexibility, though. This technique is widely applied in procedural languages (for example, "C") for controlling variables. In a true Object-Oriented Programming environment, objects are created dynamically in a pool of memory called a heap. Thus, we can say that a message "New" builds a dynamic instance of an object in the heap memory. Hence, Object-Oriented systems need a special garbage collector that automatically discovers when an object is no longer in use and destroys it. An object is eligible for garbage collection when there are no more references to that object. References that are held in a variable are usually dropped when the variable goes out of scope. Programmers can explicitly drop an object reference by setting the variable to a special null value. BankAccount myaccount = new BankAccount (12/73, 0); String myname = new String ('Nick'); // Object created file:///e /LV_CD/wbtmaster/main_library/swp2.htm (23 of 28) [10/16/2002 4:14:13 PM]

24 Employee measemployee = new Employee (myname, myaccount); // Object is used (measemployee.salary(1000)).print(); // Object destroyed measemployee = null; Remember that a program can have multiple references to the same object; all references to an object must be dropped before the object is eligible for garbage collection. 4 Reusing Classes Flexible reuse of existing components is one of the main advantages of objectoriented programming paradigm. There are basically two methods of reusing classes in Object-Oriented Languages: Composition is a method of "assembling" a new composite class from the already existing classes. They say that a composite classe reuses an implementation from its components. Inheritance may be seen simply as referring to previously defined variable definitions and methods to be reused in a new class. 4.1 Composition A simple and most frequently applied way of composition is provided by previously mentioned variable-domain relationships, i.e. by binding class variables to instances of existing classes. For example: public class Employee file:///e /LV_CD/wbtmaster/main_library/swp2.htm (24 of 28) [10/16/2002 4:14:13 PM]

25 private String Name; private BankAccount B_Account; // Methods public Object salary(object Sum) if (B_Account.transaction(Sum))return("Thanks"); else return("sorry, the firm seems to be a bankrupt!"); Here, the class "Employee" is composed of class "BankAccount", and, thus, it reuse the class "BankAccount" functionality (method "transaction" in this particular case). Actually, composition in Object-Oriented Languages is a very flexible mechanism. Thus, for example, a reusable code is identified at run-time (dynamic binding) and can be replaced dynamically to control a behavior of composed instances. For example: public class Employee private String Name; private Object B_Account; // Methods public void setbankaccount(object Account) B_Account=Account; public void salary(object Sum) B_Account.transaction(Sum); Here, an unknown functionality (method "transaction") is reused. A particular code is identified by a special method "setbankaccount". Instances of different classes may be set as a current value of the variable "B-Account", and, hence, the code "transaction" can be flexibly replaced. 4.2 Inheritance file:///e /LV_CD/wbtmaster/main_library/swp2.htm (25 of 28) [10/16/2002 4:14:13 PM]

26 Classes may be also reused by installing special relationships which form a socalled inheritance hierarchy. Basically, an inheritance relationship allows to define a class as a subclass of an existing superclass. The subclass inherits all instance variables and all methods from the superclass. For example: public class Person private String Name; // Methods public String getname() return(name); public class Employee extends Person Here, messages "getname" can be sent to instances of the class "Employee" as well as to instances of the class "Person". Defining Subclasses, programmers are allowed: add variables and methods to the ones they inherit from the superclass override inherited variables and methods, i.e. to provide specialized implementations. supress inherited variables and methods, is they are not needed. For example: public class Person private Object Name; // Methods public Object getname() file:///e /LV_CD/wbtmaster/main_library/swp2.htm (26 of 28) [10/16/2002 4:14:13 PM]

27 return(name); public class Employee extends Person private BankAccount B_Account;/* Add Variable*/ // Methods public void salary(object Sum)/* Add Method*/ B_Account.transaction(Sum); public String getname()/* Override Method*/ return(name.tostring()); 4.3 Abstract Classes Sometimes, a class that we define represents an abstract concept and, it is not supposed to be instantiated. Such classes should serve exclusively as superclasses for defining more specialized classes. For example: abstract public class Person abstract public Object getemployment(); public class Programmer extends Person public String getemployment()/* Override Method*/ return('programmer'); public class Manager extends Person public String getemployment()/* Override Method*/ return('manager'); Suppose nn abstract class defines all its methods as abstract ones. Obviously, such abstract class provides just an interface that is supported by all subclasses. In other words, an interface is a special abstract class which defines a protocol to be implemented by all subclasses. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (27 of 28) [10/16/2002 4:14:13 PM]

28 An interface does not have variables and just defines a set of methods but does not implement them. file:///e /LV_CD/wbtmaster/main_library/swp2.htm (28 of 28) [10/16/2002 4:14:13 PM]

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

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

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Inheritance (Outsource: )

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

More information

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

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

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

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

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System? Page 1 of 21 Page 2 of 21 and identity. Objects are members of a class, and the attributes and behavior of an object are defined by the class definition. The Essence of Object Oriented Programming with

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

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

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze

More information

Software Design and Analysis for Engineers

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

More information

CS112 Lecture: Defining Instantiable Classes

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

More information

EMBEDDED SYSTEMS PROGRAMMING OO Basics

EMBEDDED SYSTEMS PROGRAMMING OO Basics EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

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

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

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

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

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

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Object Oriented Technology

Object Oriented Technology Object Oriented Technology Object-oriented technology is built upon a sound engineering foundation, whose elements we collectively call the object model. The object model encompasses the principles of

More information

Student Performance Q&A:

Student Performance Q&A: Student Performance Q&A: 2004 AP Computer Science A Free-Response Questions The following comments on the 2004 free-response questions for AP Computer Science A were written by the Chief Reader, Chris

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

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

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

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

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

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

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

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

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 Inheritance

Introduction to Inheritance Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits

More information

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

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

More information

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

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

More information

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

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3 Department of Computer Science Tackling Design Patterns Chapter 4: Factory Method design pattern Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 4.1 Introduction.................................

More information

2. The object-oriented paradigm!

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

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

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Sung Hee Park Department of Mathematics and Computer Science Virginia State University September 18, 2012 The Object-Oriented Paradigm

More information

Introduction to Objects. James Brucker

Introduction to Objects. James Brucker Introduction to Objects James Brucker What is an Object? An object is a program element that encapsulates both data and behavior. An object contains both data and methods that operate on the data. Objects

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

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

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

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

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

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

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

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

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

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

More information

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

5.6.1 The Special Variable this

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

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Suppose you want to drive a car and make it go faster by pressing down on its accelerator pedal. Before you can drive a car, someone has to design it and build it. A car typically begins as engineering

More information

CS 1316 Exam 1 Summer 2009

CS 1316 Exam 1 Summer 2009 1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem

More information

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects Lecture 4: Fundamentals of Object Technology Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Credit where Credit is Due Some material presented in this lecture

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

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

CS304 Object Oriented Programming

CS304 Object Oriented Programming 1 CS304 Object Oriented Programming 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes?

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Object-Oriented

More information

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

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

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(b): Abstract classes & Polymorphism Lecture Contents 2 Abstract base classes Concrete classes Polymorphic processing Dr. Amal Khalifa,

More information

CS 1302 Chapter 9 (Review) Object & Classes

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

More information

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

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay Computer Science and Engineering Indian Institue of Technology Bombay November 27, 2004 What is Object Oriented Programming? Identifying objects and assigning responsibilities to these objects. Objects

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

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

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

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

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

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

CS111: PROGRAMMING LANGUAGE II

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

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Learn about class concepts How to create a class from which objects can be instantiated Learn about instance variables and methods How to declare objects How to organize your classes Learn about public

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

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

Java Programming Lecture 7

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

More information

Software Design COSC 4353/6353 D R. R A J S I N G H

Software Design COSC 4353/6353 D R. R A J S I N G H Software Design COSC 4353/6353 D R. R A J S I N G H Creational Design Patterns What are creational design patterns? Types Examples Structure Effects Creational Patterns Design patterns that deal with object

More information

Programming Exercise 14: Inheritance and Polymorphism

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

More information

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

9 Working with the Java Class Library

9 Working with the Java Class Library 9 Working with the Java Class Library 1 Objectives At the end of the lesson, the student should be able to: Explain object-oriented programming and some of its concepts Differentiate between classes and

More information

CSC1322 Object-Oriented Programming Concepts

CSC1322 Object-Oriented Programming Concepts CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.

More information

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

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

More information

Object Oriented Modeling

Object Oriented Modeling Object Oriented Modeling Object oriented modeling is a method that models the characteristics of real or abstract objects from application domain using classes and objects. Objects Software objects are

More information

Compaq Interview Questions And Answers

Compaq Interview Questions And Answers Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not

More information

MechEng SE3 Lecture 7 Domain Modelling

MechEng SE3 Lecture 7 Domain Modelling MechEng SE3 Lecture 7 Domain Modelling Simon Gay (slides by Phil Gray) 17 February 2010 1 This week s supplementary reading Zero Balances and Zero Responsibility Michael Bolton http://www.developsense.com/essays/zero.html

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

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

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

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1 Design Principles Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques 2-1 Data Structures Data Structure - A systematic way of organizing and accessing

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

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object

Inheritance. Unit 8. Summary. 8.1 Inheritance. 8.2 Inheritance: example. Inheritance Overriding of methods and polymorphism The class Object Unit 8 Inheritance Summary Inheritance Overriding of methods and polymorphism The class Object 8.1 Inheritance Inheritance in object-oriented languages consists in the possibility of defining a class that

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

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

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics

More information

Advanced Programming Using Visual Basic 2008

Advanced Programming Using Visual Basic 2008 Building Multitier Programs with Classes Advanced Programming Using Visual Basic 2008 The OOP Development Approach OOP = Object Oriented Programming Large production projects are created by teams Each

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

Objects and Classes: Working with the State and Behavior of Objects

Objects and Classes: Working with the State and Behavior of Objects Objects and Classes: Working with the State and Behavior of Objects 1 The Core Object-Oriented Programming Concepts CLASS TYPE FACTORY OBJECT DATA IDENTIFIER Classes contain data members types of variables

More information