Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Size: px
Start display at page:

Download "Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition"

Transcription

1 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition

2 Chapter Objectives Learn the major features of object-oriented languages Design and develop multitier applications using component-based development methods Use inheritance to extend the functionality of userdefined classes Create abstract classes that include abstract methods C# Programming: From Problem Analysis to Program Design 2

3 Chapter Objectives (continued) Distinguish the differences between sealed and abstract classes Become aware of partial classes Design and implement interfaces Understand why polymorphic programming is a common goal in.net Explore generics and learn how to create generic classes and generic methods C# Programming: From Problem Analysis to Program Design 3

4 Chapter Objectives (continued) Investigate static versus dynamic typing and become aware of when dynamic and var types are used Work through a programming example that illustrates the chapter s concepts C# Programming: From Problem Analysis to Program Design 4

5 Object-Oriented Language Features Abstraction Generalizing, identifying essential features, hiding nonessential complexities Encapsulation Packaging data and behaviors into a single unit, hiding implementation details Inheritance Extending program units to enable reuse of code Polymorphism Providing multiple (different) implementations of same named behaviors C# Programming: From Problem Analysis to Program Design 5

6 Component-Based Development Figure 11-1 Component-based development C# Programming: From Problem Analysis to Program Design 6

7 Component-Based Development (continued) Component-based applications associated with multitier applications (different layers) Business layer(s) classes that perform processing Provide functionality for specific system; provide necessary processing Data access layer - classes for accessing data from text files and databases Presentation layer - User interface tier for user interaction Graphical User Interface such as Windows or Web C# Programming: From Problem Analysis to Program Design 7

8 Component-Based Development (continued) Components facilitates reuse-based approach Define and implement independent components into systems Components are implemented through classes Takes the form of objects or collection of objects Components can then be packaged with different components and used for other applications Classes can be created that extend functionality of original classes C# Programming: From Problem Analysis to Program Design 8

9 Inheritance Enables you to: Create a general class and then define specialized classes that have access to the members of the general class Associated with an "is a" relationship Specialized class is a form of the general class Classes can also have a "has a" relationship, not associated with inheritance "has a" relationship is associated with containment or aggregation C# Programming: From Problem Analysis to Program Design 9

10 Inheriting from the Object Class Every object inherits four methods as long as reference to the System namespace included Figure 11-2 Methods inherited from an object C# Programming: From Problem Analysis to Program Design 10

11 Inheriting from Other.NET FCL Classes Experienced inheritance when you developed Windows-based programs Form you created inherited characteristics from System.Windows.Forms.Form class Already had title bar, close (X), and minimize buttons Add functionality to your programs with minimal programming Extend System.Windows.Forms.Form class to build GUIs (Button, Label, TextBox, ListBox) C# Programming: From Problem Analysis to Program Design 11

12 Inheriting from Other.NET FCL Classes Derived class Figure 11-3 Derived class Base class Class listed after the colon is base class class that already has some functionality Class to the left, PresentationGUI, is derived class Derived class is the new class, the user-defined class C# Programming: From Problem Analysis to Program Design 12

13 Creating Base Classes for Inheritance Can define your own classes from which other classes can inherit Base class is called the super or parent class Base class has Data members defined with a private access modifier Constructors defined with public access modifiers Properties offering public access to data fields C# Programming: From Problem Analysis to Program Design 13

14 Creating Base Classes for Inheritance Might create a generalized class such as person public class Person { private string idnumber; private string lastname; private string firstname; private int age; Data members C# Programming: From Problem Analysis to Program Design 14

15 Access Modifiers Class members defined with private access are restricted to members of the current class Data members are defined with private access modifier Private access enables class to protect its data and only allow access to the data through its methods or properties Constructors use public access modifier If they are not public, you would not be able to instantiate objects of the class in other classes Constructors are methods Named the same name as class and has no return type C# Programming: From Problem Analysis to Program Design 15

16 Creating Base Classes for Inheritance // Constructor with zero arguments public Person( ) { } // Constructor with four arguments public Person (string id, string lname, string fname, int anage) { } idnumber = id; lastname = lname; firstname = fname; age = anage; Continued definition for Person class Notice, constructor is a method, has same name as class (Person), has no return type, and is overloaded C# Programming: From Problem Analysis to Program Design 16

17 Access Modifiers Properties offer public access to data fields Properties look like data fields, but are implemented as methods Properties provide the getters (accessors) and setters (mutators) for the class Make properties read-only by NOT defining the set Properties often named the same name as their associated data member EXCEPT, property uses Pascal case (starts with capital letter) LastName lastname C# Programming: From Problem Analysis to Program Design 17

18 Properties // Property for last name public string LastName { } get { } set { } Private data member return lastname; lastname = value; Properties defined with public access they provide access to private data No need to declare value. It is used, almost like magic value refers to the value sent through an assignment statement get, set and value are contextual keywords C# Programming: From Problem Analysis to Program Design 18

19 Overriding Methods Person class example has two additional methods public override string ToString( ) // Defined in Person public virtual int GetSleepAmt( ) // Defined in Person Can replace a method defined at a higher level with a new definition Use keyword override in method heading in derived class to provide a new definition In order to be an method that can be overridden, keywords virtual, abstract, or override must be part of the heading for the parent class C# Programming: From Problem Analysis to Program Design 19

20 Overriding Methods Should override the object ToString( ) method Figure 11-4 ToString( ) signature Object s ToString( ) method The Person class example overrides ToString( ) public override string ToString( ) // Defined in Person { return firstname + " " + lastname; } C# Programming: From Problem Analysis to Program Design 20

21 Virtual Methods (continued) ToString( ) uses the virtual modifier in the Object class, implying that any class can override it ToString( ) method can have many different definitions Example of polymorphism Overriding differs from overloading a method Overridden methods have exactly the same signature Overloaded methods each have a different signature C# Programming: From Problem Analysis to Program Design 21

22 Creating Derived Classes Derived classes inherit from a base class Derived classes also called subclasses or child classes Derived classes do not have access to change data members defined with private access in the parent or base class Derived classes have access to change data members defined with protected access in the parent or base class C# Programming: From Problem Analysis to Program Design 22

23 Derived Classes public class Student : Person // Student is derived from Person { private string major; private string studentid; Additional data members public Student( ) { } // Default constructor :base( ) // No arguments sent to base constructor. Indicates which base class constructor to use C# Programming: From Problem Analysis to Program Design 23

24 Calling the Base Constructor To call the constructor for the base class, add keyword :base between the constructor heading for the subclass and the opening curly brace public Student(string id, string fname, string lname, string maj, int sid) :base (id, lname, fname) // base constructor arguments {... Use base constructor with int and two strings arguments Base constructor must have a constructor with matching signature C# Programming: From Problem Analysis to Program Design 24

25 Calling the Base Constructor (continued) Student astudent = new Student (" ", "Maria", "Woo", "CS", "1111"); First three arguments, " ", "Maria", and "Woo", are sent to the constructor for Person class Last two arguments ("CS", "1111") are used by the Student class constructor (for example above) Student anotherstudent = new Student( ); Both Person and Student default constructors (with no parameters) are called when Student( ) is invoked C# Programming: From Problem Analysis to Program Design 25

26 Using Members of the Base Class Derived classes can directly access any members defined with public or protected access modifiers Objects instantiated from sub classes (like Student) can use any public members of subclass or base class anotherstudent.lastname = "Garcia"; C# Programming: From Problem Analysis to Program Design 26

27 Calling Overridden Methods of Scope the Base Class Methods defined in subclass take precedence when named the same name as member of a parent class Use keyword base before the method name to call an overridden method of the base class return base.getsleepamt( ) // Calls GetSleepAmt( ) in // parent class Review PresentationGUIWithOneProject_NoDLLs_FirstExample C# Programming: From Problem Analysis to Program Design 27

28 Relationship between the Person and Student Classes Figure 11-5 Inheritance class diagram C# Programming: From Problem Analysis to Program Design 28

29 Making Stand-Alone Components Can take Person and Student classes (or any userdefined class) and store in library for future use Compile class and create an assembly Assemblies are units configured and deployed in.net Classes can be compiled and stored as a dynamic link library (DLL) instead of into the EXE file type C# Programming: From Problem Analysis to Program Design 29

30 Dynamic Link Library (DLL) Several options for creating components One option compile source code into.dll file type Once you have DLL, any application that wants to use it just adds a reference to the DLL That referenced file with the.dll extension becomes part of the application s private assembly Can use the command line to create.dll C# Programming: From Problem Analysis to Program Design 30

31 Using Visual Studio to Create DLL Files Figure 11-6 Creating a DLL component C# Programming: From Problem Analysis to Program Design 31

32 Build Instead of Run to Create DLL Create the parent class first in order to use IntelliSense (for sub classes) To illustrate creating stand-along components, separate project created for Person and Student Because Visual Studio assigns the namespace name the same name as the project name (Person), you should change the namespace identifier If you don t change it, when you start adding a reference to a created DLL, it can become confusing Changed to PersonNamespace for the example C# Programming: From Problem Analysis to Program Design 32

33 Build Instead of Run to Create DLL After typing class, do not run it select BUILD, Build Solution Figure 11-7 Attempting to run a class library file Create new project for subclasses (Student) Again, select Class Library template from Start page Change namespace identifier (StudentNamespace) C# Programming: From Problem Analysis to Program Design 33

34 Build Instead of Run to Create DLL (continued) Add a new using statement to subclass In Student, add using PersonNamespace; To gain access to base class members in subclass, Add Reference in subclass to base class Use Solution Explorer window DLL is stored in Debug directory under the bin folder wherever you create the project C# Programming: From Problem Analysis to Program Design 34

35 Add Reference to Base Class One of the first things to do is Add a Reference to the Parent DLL Figure 11-8 Adding a reference to a DLL C# Programming: From Problem Analysis to Program Design 35

36 Add Reference to Base Class (continued) Use Browse button to locate DLL Figure 11-9 Add Reference dialog box C# Programming: From Problem Analysis to Program Design 36

37 Add Reference to Base Class (continued) Figure Locating the Person.dll component C# Programming: From Problem Analysis to Program Design 37

38 Adding a New Using Statement In the subclass class, if you simply type the following, you receive an error message public class Student : Person Figure Namespace reference error C# Programming: From Problem Analysis to Program Design 38

39 Adding a New Using Statement (continued) To avoid error, could type: public class Student : PersonNamespace.Person Notice fully qualified name Better option is to add a using directive using PersonNamespace; // Use whatever name you // typed for the namespace for Person After typing program statements, build the DLL from the Build option under the BUILD menu bar C# Programming: From Problem Analysis to Program Design 39

40 Creating a Client Application to Use the DLL DLL components can be reused with many different applications Once the.dll is in the library, any number of applications can reference it Instantiate objects of the referenced DLL Two steps Required Add a reference to the DLL components Include a using statement with the namespace name C# Programming: From Problem Analysis to Program Design 40

41 Creating a Client Application to Use the DLL (continued) Figure DLLs referenced in the PresentationGUI class C# Programming: From Problem Analysis to Program Design 41

42 Declaring an Object of the Component Type Declare object of the subclass (Student) not the base class public class PresentationGUI : System.Windows.Forms.Form { private Student astudent; Instantiate the object astudent = new Student(" ", "Maria", "Woo", "CS", "1111"); Use members of the derived, base, or referenced classes Review PresentationGUIwithDLLs (and/or LibraryFiles) Examples C# Programming: From Problem Analysis to Program Design 42

43 Creating a Client Application to Use the DLL (continued) Figure PresentationGUI output referencing two DLLs C# Programming: From Problem Analysis to Program Design 43

44 Using ILDASM to View the Assembly (ILDASM): Intermediate Language Disassembler tool Assembly shows the signatures of all methods, data fields, and properties One option display the source code as a comment in the assembly Can be run from the command line or from within the Visual Studio IDE C# Programming: From Problem Analysis to Program Design 44

45 Using ILDASM to View the Assembly (continued) In order to use ILDASM in Visual Student, must be added as an external tool in Visual Studio (TOOLS, External Tools ) DLL files cannot be modified or viewed as source code Can use ILDASM to view DLL assemblies C# Programming: From Problem Analysis to Program Design 45

46 ILDASM to View the Assembly Data fields.ctors are constructors IL code for the method Properties converted to methods Figure Student.dll assembly from ILDASM C# Programming: From Problem Analysis to Program Design 46

47 Abstract Classes Useful for implementing abstraction Identify and pull out common characteristics that all objects of that type possess Class created solely for the purpose of inheritance Provide a common definition of a base class so that multiple derived classes can share that definition For example, Person Student, Faculty Person defined as base abstract class Student defined as derived subclass C# Programming: From Problem Analysis to Program Design 47

48 Abstract Classes Add keyword abstract on class heading [access modifier] abstract class ClassIdentifier { } // Base class Started new project used same classes, added abstract to heading of Person base class (PresentationGUIWithAbstractClassAndInterface Example) public abstract class Person C# Programming: From Problem Analysis to Program Design 48

49 Abstract Classes Abstract classes used to prohibit other classes from instantiating objects of the class Can create subclasses (derived classes) of the abstract class Derived classes inherit characteristics from base abstract class Objects can only be created using classes derived from the abstract class C# Programming: From Problem Analysis to Program Design 49

50 Abstract Methods Only permitted in abstract classes Method has no body Implementation details of the method are left up to classes derived from the base abstract class Every class that derives from the abstract class must provide implementation details for all abstract methods Sign a contract that details how to implement its abstract methods C# Programming: From Problem Analysis to Program Design 50

51 Abstract Methods (continued) No additional special keywords are used when a new class is defined to inherit from the abstract base class [access modifier] abstract returntype MethodIdentifier ([parameter list]) ; // No { } included Declaration for abstract method ends with semicolon; NO method body or curly braces Syntax error if you use the keyword static or virtual when defining an abstract method C# Programming: From Problem Analysis to Program Design 51

52 Abstract Methods (continued) // Classes that derive from Person // must provide implementation details // (the body for the method) public abstract string GetExerciseHabits( ); In the derived class, all abstract methods headings include the special keyword override public override string GetExerciseHabits() { } return "Exercises daily"; Defined in Person Defined in Student C# Programming: From Problem Analysis to Program Design 52

53 Sealed Classes Sealed class cannot be a base class Sealed classes are defined to prevent derivation Objects can be instantiated from the class, but subclasses cannot be derived from it public sealed class SealedClassExample Number of.net classes defined with the sealed modifier Pen and Brushes classes C# Programming: From Problem Analysis to Program Design 53

54 Sealed Methods If you do not want subclasses to be able to provide new implementation details, add the keyword sealed Helpful when a method has been defined as virtual in a base class Don t seal a method unless that method is itself an override of another method in some base class C# Programming: From Problem Analysis to Program Design 54

55 Partial Classes Break class up into two or more files Each file uses partial class designation Used by Visual Studio for Windows applications Code to initialize controls and set properties is placed in a somewhat hidden file in a region labeled Windows Form Designer generated code File is created following a naming convention of FormName.Designer.cs or xxx.designer.cs Second file stores programmer code At compile time, the files are merged together C# Programming: From Problem Analysis to Program Design 55

56 Creating Partial Classes All the files must use the partial keyword All of the partial class definitions must be defined in the same assembly (.exe or.dll file) Class name and accessibility modifiers, such as private or public, must also match // class definition split into two or more source files public partial class ClassIdentifier C# Programming: From Problem Analysis to Program Design 56

57 Interfaces C# supports single inheritance Classes can implement any number of interfaces Only inherit from a single class, abstract or nonabstract Think of an interface as a class that is totally abstract; all methods are abstract Abstract classes can have abstract and regular methods Classes implementing interface agree to define details for all of the interface s methods C# Programming: From Problem Analysis to Program Design 57

58 General form Interfaces (continued) [modifier] interface InterfaceIdentifier { } // members - no access modifiers are used Members can be methods, properties, or events No implementations details are provided for any of its members C# Programming: From Problem Analysis to Program Design 58

59 Defining an Interface Can be defined as member of existing namespace or class OR by compiling it to separate DLL Easy approach is to put the interface in a separate project (like was done with Person and Student) Use the Class Library template from Start page Unlike abstract classes, it is not necessary to use the abstract keyword with methods of interfaces Because all methods are abstract Review LibraryFiles Example C# Programming: From Problem Analysis to Program Design 59

60 Defining an Interface (continued) Figure ITraveler interface To store in Class Library, Build the interface DLL using Build option from BUILD menu C# Programming: From Problem Analysis to Program Design 60

61 Implement the Interface Follow same steps as with the Person and Student DLLs if you want to store in Class Library Create Class Library File from Start page Compile and Build assembly from BUILD menu option, creating a.dll file In the class implementing the interface, Add Reference to the.dll file Type a using statement (for the namespace identifier) in the class implementing the interface C# Programming: From Problem Analysis to Program Design 61

62 Implement the Interface (continued) Heading for the class implementing the interface identifies base class and one or more interfaces following the colon (:) [Base class comes first] [modifier] class ClassIdentifier : identifier [, identifier] public class Student : Person, Itraveler For testing purposes, PresentationGUI class in the PresentationGUIAbtractClassAndInterface folder modified to include calls to interface methods Review PresentationGUIWithAbstractClassAndInterface Example C# Programming: From Problem Analysis to Program Design 62

63 Implement the Interface: PresentationGUI Application Populated by Interface methods Figure PresentationGUI output using interface methods C# Programming: From Problem Analysis to Program Design 63

64 Implement the Interface: PresentationGUI Application GetStartLocation( ), GetDestination( ), and DetermineMiles( ) members of ITraveler interface private void btntravel_click(object sender, EventArgs e) { // GetStartLocation( ), GetDestination( ) and DetermineMiles( ) // methods all defined as abstract methods in ITraveler interface txtbxfrom.text = astudent.getstartlocation(); txtbxto.text = astudent.getdestination(); txtbxmiles.text = astudent.determinemiles().tostring(); txtbxfrom.visible = true; //More statements C# Programming: From Problem Analysis to Program Design 64

65 .NET Framework Interfaces Play an important role in the.net Framework Collection classes such as Array class and HashTable class implement a number of interfaces Designing the classes to implement interfaces provides common functionality among them C# Programming: From Problem Analysis to Program Design 65

66 .NET Framework Interfaces (continued).net Array class is an abstract class Array implements several interfaces (ICloneable; IList; ICollection; and IEnumerable) Includes methods for manipulating arrays, such as: Iterating through the elements Searching by adding elements to the array Copying, cloning, clearing, and removing elements from the array Reversing elements Sorting Much of functionality is in place because of the contracts the interfaces are enforcing C# Programming: From Problem Analysis to Program Design 66

67 Polymorphism Polymorphism is implemented through interfaces, inheritance, and the use of abstract classes Ability for classes to provide different implementations details for methods with same name Determines which method to call or invoke at run time based on which object calls the method (Dynamic binding) Example ToString( ) method Through inheritance, polymorphism is made possible by allowing classes to override base class members C# Programming: From Problem Analysis to Program Design 67

68 Polymorphic Programming in.net Multiple classes can implement the same interface, each providing different implementation details for its abstract methods Black box concept Classes that derive from abstract classes are forced to include implementation details for any abstract method C# Programming: From Problem Analysis to Program Design 68

69 Polymorphic Programming in.net (continued) Actual details of the body of interface methods are left up to the classes that implement the interface Method name is the same Every class that implements the interface may have a completely different behavior C# Programming: From Problem Analysis to Program Design 69

70 Generics Reduce the need to rewrite algorithms for each data type Create generic classes, delegates, interfaces, and methods Identify where data will change in the code segment by putting a placeholder in the code for the type parameters C# Programming: From Problem Analysis to Program Design 70

71 Generic Classes Defined by inserting an identifier between left and right brackets on the class definition line Example public class GenericClass <T> { } public T datamember; //To instantiate an object, replace the T with data type GenericClass <string> anidentifer = new GenericClass <string>( ); C# Programming: From Problem Analysis to Program Design 71

72 Generic Classes (continued) public class Stack<T> { private T[ ] items; private int stackpointer = 0; public Stack(int size) { items = new T[size]; } Generic Stack class C# Programming: From Problem Analysis to Program Design 72

73 Generic Classes (continued) public T Pop( ) { return items[--stackpointer]; } public void Push(T anitem) { items[stackpointer] = anitem; stackpointer++; } } Review GenericStack Example C# Programming: From Problem Analysis to Program Design 73

74 Generic Methods Similar to defining a generic class Can define generic methods that are not part of generic classes Insert identifier between left and right brackets on the method definition line to indicate it is a generic method Then place that identifier either in the parameter list or as a return type or in both places C# Programming: From Problem Analysis to Program Design 74

75 Generic Methods (continued) public void SwapData <T> (ref T first, ref T second) { T temp; temp = first; first = second; second = temp; } //To call the method, specify the type following method name SwapData <string> (ref firstvalue, ref secondvalue); C# Programming: From Problem Analysis to Program Design 75

76 Dynamic C# was originally characterized as being a strongly typed language Compiler checks to ensure that only compatible values are attempting to be stored Variables can still be defined as objects and then cast as different data types during run time Additional boxing/unboxing is needed C# Programming: From Problem Analysis to Program Design 76

77 Dynamic Data Type Object defined using the dynamic keyword can store anything No unboxing or casting is necessary prior to their use With dynamic data types, the type checking occurs at run time Once defined as dynamic, the memory location can hold any value Dynamic types can be used for data types, method parameters or method return types C# Programming: From Problem Analysis to Program Design 77

78 Dynamic Data Type (continued) dynamic intvalue = 1000; dynamic stringvalue = "C#"; dynamic decimalvalue = 23.45m; dynamic adate = System.DateTime.Today; Console.WriteLine("{0} {1} {2} {3}", intvalue, stringvalue, decimalvalue, adate); 1000C# /16/ :00:00 AM Single dynamic memory location can hold values of different data types C# Programming: From Problem Analysis to Program Design 78

79 var Data Type Variables declared inside a method can be declared using the var keyword Implicitly typed by the compiler - compiler determines the type One primary difference between dynamic and var is that var data items must be initialized when they are declared Can declare a dynamic memory location and later associate values with it C# Programming: From Problem Analysis to Program Design 79

80 var Data Type (continued) var somevalue = 1000; Implicitly typed by the compiler Compiler determines the type Compiler infers the type of the variable from the expression on the right side of the initialization statement C# Programming: From Problem Analysis to Program Design 80

81 StudentGov Application Example Figure Problem specification for StudentGov example C# Programming: From Problem Analysis to Program Design 81

82 StudentGov Application Example (continued) Table 11-1 Data fields organized by class C# Programming: From Problem Analysis to Program Design 82

83 StudentGov Example (continued) Figure Prototype for StudentGov example C# Programming: From Problem Analysis to Program Design 83

84 StudentGov Example (continued) Figure Class diagrams for StudentGov example C# Programming: From Problem Analysis to Program Design 84

85 StudentGov Example (continued) Figure References added to StudentGov example C# Programming: From Problem Analysis to Program Design 85

86 StudentGov Example (continued) Figure References added to StudentGov example (continued) C# Programming: From Problem Analysis to Program Design 86

87 StudentGov Example (continued) Table 11-2 PresentationGUI property values C# Programming: From Problem Analysis to Program Design 87

88 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 88

89 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 89

90 StudentGov Example (continued) Table 11-2 PresentationGUI property values (continued) C# Programming: From Problem Analysis to Program Design 90

91 StudentGov Example (continued) Figure Setting the StartUp Project C# Programming: From Problem Analysis to Program Design 91

92 StudentGov Application Example (continued) Figure Part of the PresentationGUI assembly C# Programming: From Problem Analysis to Program Design 92

93 StudentGov Application Example (continued) Figure Output from StudentGov example C# Programming: From Problem Analysis to Program Design 93

94 Coding Standards Declare members of a class of the same security level together When declaring methods that have too many arguments to fit on the same line, the leading parenthesis and the first argument should be written on the same line Additional arguments are written on the following line and indented C# Programming: From Problem Analysis to Program Design 94

95 Resources Comparison of Unified Modeling Language Tools Generic Classes (C# Programming Guide) C# Station Tutorial: Interfaces C# Programming: From Problem Analysis to Program Design 95

96 Chapter Summary Major features of object-oriented languages Abstraction Encapsulation Inheritance Polymorphism Multitier applications using component-based development methods C# Programming: From Problem Analysis to Program Design 96

97 Chapter Summary (continued) Use inheritance to extend the functionality of userdefined classes Abstract classes Abstract methods Sealed classes Partial classes C# Programming: From Problem Analysis to Program Design 97

98 Chapter Summary (continued) Interfaces Why polymorphic programming? Generics Generic classes Generic methods Dynamic data types var data types C# Programming: From Problem Analysis to Program Design 98

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives 2 Chapter

More information

Chapter 5 Object-Oriented Programming

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

More information

Object-Oriented Programming in C# (VS 2012)

Object-Oriented Programming in C# (VS 2012) Object-Oriented Programming in C# (VS 2012) This thorough and comprehensive course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes the C#

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 02 Features of C#, Part 1 Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 Module Overview Constructing Complex Types Object Interfaces and Inheritance Generics Constructing

More information

Object-Oriented Programming in C# (VS 2015)

Object-Oriented Programming in C# (VS 2015) Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes

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

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Course Number: 6367A Course Length: 3 Days Course Overview This three-day course will enable students to start designing

More information

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Chapter 12 OOP: Creating Object-Oriented Programs McGraw-Hill 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter Objectives - 1 Use object-oriented terminology correctly Create a two-tier

More information

C# Programming: From Problem Analysis to Program Design. Fourth Edition

C# Programming: From Problem Analysis to Program Design. Fourth Edition C# Programming: From Problem Analysis to Program Design Fourth Edition Preface xxi INTRODUCTION TO COMPUTING AND PROGRAMMING 1 History of Computers 2 System and Application Software 4 System Software 4

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

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

Introduction to Programming Using Java (98-388)

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

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005 Objectives After studying this chapter, you should be able to: Explain the history of programming languages

More information

CS-202 Introduction to Object Oriented Programming

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

More information

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

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

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

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

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5, Informatik II Tutorial 6 Mihai Bâce mihai.bace@inf.ethz.ch 05.04.2017 Mihai Bâce April 5, 2017 1 Overview Debriefing Exercise 5 Briefing Exercise 6 Mihai Bâce April 5, 2017 2 U05 Some Hints Variables &

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

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

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 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Chapter 12 OOP: Creating Object- Oriented Programs McGraw-Hill Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Objectives (1 of 2) Use object-oriented terminology correctly. Create

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, Polymorphism, and Interfaces Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)

More information

Inheritance. Transitivity

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

More information

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

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

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

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use

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

Informatik II Tutorial 6. Subho Shankar Basu

Informatik II Tutorial 6. Subho Shankar Basu Informatik II Tutorial 6 Subho Shankar Basu subho.basu@inf.ethz.ch 06.04.2017 Overview Debriefing Exercise 5 Briefing Exercise 6 2 U05 Some Hints Variables & Methods beginwithlowercase, areverydescriptiveand

More information

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class. 1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

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

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

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

Saikat Banerjee Page 1

Saikat Banerjee Page 1 1. What s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each

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

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW Prepared by: Dr. Abdallah Mohamed, AOU-KW 1 1. Introduction 2. Objects and classes 3. Information hiding 4. Constructors 5. Some examples of Java classes 6. Inheritance revisited 7. The class hierarchy

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved. Chapter 9 Objects and Classes 1 Objectives Classes & Objects ( 9.2). UML ( 9.2). Constructors ( 9.3). How to declare a class & create an object ( 9.4). Separate a class declaration from a class implementation

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

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Chapter 4 Defining Classes I

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

More information

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

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

Course Syllabus C # Course Title. Who should attend? Course Description

Course Syllabus C # Course Title. Who should attend? Course Description Course Title C # Course Description C # is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the.net Framework.

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

CLASSES AND OBJECTS IN JAVA

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

More information

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:

More information

ITI Introduction to Computing II

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

More information

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

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts ISBN 0-321-49362-1 Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

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

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

C# Language. CSE 409 Advanced Internet Technology

C# Language. CSE 409 Advanced Internet Technology C# Language Today You will learn Building a basic class Value Types and Reference Types Understanding Namespaces and Assemblies Advanced Class Programming CSE 409 Advanced Internet Technology Building

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

BBM 102 Introduction to Programming II Spring Inheritance

BBM 102 Introduction to Programming II Spring Inheritance BBM 102 Introduction to Programming II Spring 2018 Inheritance 1 Today Inheritance Notion of subclasses and superclasses protected members UML Class Diagrams for inheritance 2 Inheritance A form of software

More information

Informatik II (D-ITET) Tutorial 6

Informatik II (D-ITET) Tutorial 6 Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 10 Creating Classes and Objects Objectives After studying this chapter, you should be able to: Define a class Instantiate an object from a class

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

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

ITI Introduction to Computing II

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

More information

DOT NET Syllabus (6 Months)

DOT NET Syllabus (6 Months) DOT NET Syllabus (6 Months) THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In- Time Compilation and CLS Disassembling.Net Application to IL

More information

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

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

More information

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal COMSC-051 Java Programming Part 1 Part-Time Instructor: Joenil Mistal Chapter 4 4 Moving Toward Object- Oriented Programming This chapter provides a provides an overview of basic concepts of the object-oriented

More information

DOT NET SYLLABUS FOR 6 MONTHS

DOT NET SYLLABUS FOR 6 MONTHS DOT NET SYLLABUS FOR 6 MONTHS INTRODUCTION TO.NET Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

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

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

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

More information

CO Java SE 8: Fundamentals

CO Java SE 8: Fundamentals CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator

More information

Programming II (CS300)

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

More information

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.) INTRODUCTION TO.NET Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.) CLR Architecture and Services The.Net Intermediate Language (IL) Just- In-

More information

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including: Abstraction Encapsulation Inheritance and Polymorphism Object-Oriented

More information

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank

Uka Tarsadia University MCA ( 3rd Semester)/M.Sc.(CA) (1st Semester) Course : / Visual Programming Question Bank Unit 1 Introduction to.net Platform Q: 1 Answer in short. 1. Which three main components are available in.net framework? 2. List any two new features added in.net framework 4.0 which is not available in

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

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

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

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Learning C# 3.0 Jesse Liberty and Brian MacDonald O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Table of Contents Preface xv 1. C# and.net Programming 1 Installing C# Express 2 C# 3.0

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Ch02. True/False Indicate whether the statement is true or false.

Ch02. True/False Indicate whether the statement is true or false. Ch02 True/False Indicate whether the statement is true or false. 1. The base class inherits all its properties from the derived class. 2. Inheritance is an is-a relationship. 3. In single inheritance,

More information

Abstract data types &

Abstract data types & Abstract Data Types & Object-Oriented Programming COS 301 - Programming Languages Chapters 11 & 12 in the book Slides are heavily based on Sebesta s slides for the chapters, with much left out! Abstract

More information

Abstract Data Types & Object-Oriented Programming

Abstract Data Types & Object-Oriented Programming Abstract Data Types & Object-Oriented Programming COS 301 - Programming Languages Chapters 11 & 12 in the book Slides are heavily based on Sebesta s slides for the chapters, with much left out! Abstract

More information

Object-Oriented Programming

Object-Oriented Programming - oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

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

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

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

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

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET 2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET Introduction Elements of this syllabus are subject to change. This five-day instructor-led course provides students with the knowledge

More information

Course Hours

Course Hours Programming the.net Framework 4.0/4.5 with C# 5.0 Course 70240 40 Hours Microsoft's.NET Framework presents developers with unprecedented opportunities. From 'geoscalable' web applications to desktop and

More information

CHAPTER 1: INTRODUCING C# 3

CHAPTER 1: INTRODUCING C# 3 INTRODUCTION xix PART I: THE OOP LANGUAGE CHAPTER 1: INTRODUCING C# 3 What Is the.net Framework? 4 What s in the.net Framework? 4 Writing Applications Using the.net Framework 5 What Is C#? 8 Applications

More information