PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, OCTOBER 2017 Programming Using C#.NET (13MCA53) Solution Set Faculty: Jeny Jijo

Size: px
Start display at page:

Download "PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, OCTOBER 2017 Programming Using C#.NET (13MCA53) Solution Set Faculty: Jeny Jijo"

Transcription

1 PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, OCTOBER 2017 Programming Using C#.NET (13MCA53) Solution Set Faculty: Jeny Jijo 1. What is Encapsulation? Explain the two ways of enforcing encapsulation with suitable examples.[10] Encapsulation: * Hides unnecessary implementation details from the object user. (i.e.) no need to worry about the numerous lines of code that are working behind the scenes to carry out the work. * Data Protection (i.e.) Rather than defining public fields, you should get in the habit of defining private data fields, which are indirectly manipulated by the caller using one of the two main techniques. ** Define a pair of Traditional Accessor and Mutator methods ** Define a named property Defining a pair of Traditional Accessor and Mutator methods: Defining an accessor (get method) and mutator (set method) is one way of accessing the private data field. (e.g.) public class employee private string name; public string getname() return name; public void setname(string n) name=n; class empapp public static void Main() employee o=new employee(); o.setname( XYZ ); Console.WriteLine(o.getname()); Property: * Drawbacks of Traditional accessor and mutator methods are: * Code manually * Users have to remember that they have to use accessor methods to work with data members. * Using a property, a programmer can get access to data members as though they are public fields. (e.g.) public class employee private string name; public string name1 get return name; set name=value;

2 The get and set logic is both public. * A property that has only a getter is called a read-only property * A property that has only a setter is called write-only property * Static properties 2. (a) Explain is-a and has-a relationships with respect to inheritance? [5] Classical inheritance ( is-a relationship): * Single * Multilevel * Hierarchical inheritance When we establish is-a relationships between classes, we are building a dependency between two or more class types. The basic idea behind the classical inheritance is that new classes may extend the functionality of existing classes. Containment / Delegation model ( has-a relationship): (e.g.) public class deductions public int deduct() return 1000; public class employee protected deductions empdeduct=new deductions(); public deductions ded get return empdeduct; set empdeduct=value; public class containment public static void Main() employee ob=new employee(); Console.WriteLine(ob.ded.deduct()); (b) How do you prevent inheritance using sealed classes? Explain with example. [5] Sealed Class: * A class that cannot be sub-classed is called Sealed class. * This is achieved in C# using the modifier sealed. * Declaring a class sealed prevents any unwanted extensions to the class (e.g.) sealed class A.. Sealed Method: * When an instance method declaration includes the sealed modifier, the method is said to be a sealed method.

3 * It means a derived class cannot override this method, but a sealed method can be used to override an inherited virtual method with the same signature. * Always used along with override modifer. (e.g.) class A public virtual void add() class B:A public sealed override void add(). 3 (a) What are Exceptions? List out the core members of system exception class [6] Programming with structured exception handling involves the use of 4 interrelated entities A class type that represents the details of the exception that occured A member that throws an instance of the exception class to the caller. A block of code on the callers side that invokes the exception-prone member A block of code on the callers side that will process(or catch) the exception should it occur. The C# programming language offers four keywords Try Catch Throw Finally System.Exception: * All user and system-defined exceptions are derived from System.Exception base class. Core Members of System.Exception: 1)HelpLink: This virtual property returns a URL to a help file describing the error in full detail. 2) Message: This virtual read-only (get) property returns the textual description of a given error. The error message itself is set as a constructor parameter. 3) Source: This virtual property returns the name of the assembly that threw the exception. 4) TargetSite: This read-only property returns a MethodBase type, which describes numerous details about the method that threw the exception. 5) StackTrace: This virtual read-only property contains a string that identifies the sequence of calls that triggered the exception. 6) Data: This virtual read-only property retrieves a collection of key/value pairs that provides additional, user-defined information about the exception. 7) InnerException: This read-only property can be used to obtain information about the previous exception that caused the current exception to occur.

4 (b) Give an example for throwing a generic exception. [04] class Program static void Main(string[]args) int[] a = new int[2]; int c; try a[0] = 0; a[1] = 1; Console.WriteLine("Enter a value:"); c = int.parse(console.readline()); if (c < 0) throw new ArgumentOutOfRangeException("value not within the range"); if (c == 0) throw new DivideByZeroException("Cannot divide by zero"); else Console.WriteLine("Division = 0", a[1] / c); catch (IndexOutOfRangeException e1) Console.WriteLine(e1.Message); catch (ArgumentOutOfRangeException e2) Console.WriteLine(e2.Message); catch (DivideByZeroException e3) Console.WriteLine(e3.Message); catch (Exception e) Console.WriteLine("Exception in general"); Console.WriteLine(e.Message); finally Console.ReadLine(); Console.WriteLine("\n\nFinally section will always occur");

5 4) Explain i) Indexers [5] Indexers are location indicators which are used to access class objects just like accessing elements in an array. They are useful in cases where a class is a container for other objects 1. An indexer takes an index argument and looks like an array 2. The indexer is declared using the name this Egpublic double this[int idx] get... set... The implementation rules for get and set are same as for properties. The parameter inside the square bracket is used as index. ii) Partial classes [5] Partial class is a class that enables you to specify the definition of a class,structure or interface in two or more source files. All d source files, each containing a section of the class defn, combine when the application is complete. Required when working on large projects Distributes a class over multiple separate files allowing developers to work on the class simultaneously Declare a partial class using keyword partial public partial class student public void marks() 5 (a) What are Extension methods? [3] Helps to extend a class without creating a new derived class Work as a static method, but is invoked with an instance of the extended class It uses the this keyword before its first parameter Only a class that has static member and implements the this keyword in the first parameter of a static method can use the extension methods static class myclass public static int extmethod(this string Number ) return Int32.Parse(Number); public static int mystaticmethod(string Number) return Int32.Parse(Number); class mainclass static void Main(strings [] args) string Number = 100 ; int ext=number.extmethod(); C.Wl(ext); int stat = myclass.mystaticmethod(number); C.Wl(stat);

6 (b) Explain the types of compile time and runtime polymorphism [7] Types of Polymorphism: Operation polymorphism: * This is been implemented using overloaded methods and operators * The overloaded methods are selected for invoking by matching arguments, in terms of number, type and order. * This information is known to the compiler at the time of compilation and therefore the compiler is able to select and bind the appropriate method to the object for a particular call at compile time itself. (Early binding, Static binding, static linking or Compile-time polymorphism) * Multiple methods with the same name are created. However, the parameters on each method vary. using System; class employee public int empid=101; public string empname="xyz"; public employee() Console.WriteLine("01",empid, empname); public void emp (int id) Console.WriteLine("0",id); public void emp (int id, string name) Console.WriteLine("01",id, name); class operation public static void Main() employee ob=new employee(); ob.emp(20); ob.emp(30,"sss"); Inclusion Polymorphism: * This is been implemented using virtual functions. * The selection of appropriate method is done dynamically at runtime * The decision on exactly which method to call is delayed until runtime. (Late binding, Dynamic binding, runtime polymorphism) C# permits upcasting of an object of a derived class to an object of its base class. class Base class Derived:Base

7 Base b=new Derived(); // upcasting Derived d=new Base(); // Error using System; class fruits public virtual void display() Console.WriteLine("FRUITS"); class apple:fruits public override void display() Console.WriteLine("APPLE"); class orange:fruits public override void display() Console.WriteLine("ORANGE"); class inclusion public static void Main() //fruits ob=new fruits(); //ob.display(); fruits ob=new apple(); ob.display(); fruits ob=new orange(); ob.display(); 6) What are abstract classes? Bring out the difference between abstract base classes and interfaces. [10] Interface Types vs. Abstract Base Classes when a class is marked as abstract, it may define any number of abstract members to provide a polymorphic interface to all derived types. However, even when a class does define a set of abstract members, it is also free to define any number of constructors, field data, nonabstract members (with implementation), and so on. Interfaces, on the other hand, only contain abstract member definitions. The polymorphic interface established by an abstract parent class suffers from one major limitation in that only derived types support the members defined by the abstract parent. However, in larger software systems, it is very common to develop multiple class hierarchies that have no common parent beyond System.Object. Given that abstract members in an abstract base class apply only to derived types, we have no way to configure types in different hierarchies to support the same polymorphic interface. By way of example, assume you have defined the following abstract class: abstract class CloneableType // Only derived types can support this // "polymorphic interface." Classes in other // hierarchies have no access to this abstract // member. public abstract object Clone(); Given this definition, only members that extend CloneableType are able to support the Clone() method. If you create a new set of classes that do not extend this base class, you can t gain this polymorphic interface. Also you may recall, that C# does not support multiple inheritance for classes. Therefore, if you wanted to create a MiniVan that is-a Car and is-a CloneableType, you are unable to do so: // Nope! Multiple inheritance is not possible in C# // for classes. public class MiniVan : Car, CloneableType

8 As you would guess, interface types come to the rescue. Once an interface has been defined, it can be implemented by any class or structure, in any hierarchy, within any namespace or any assembly (written in any.net programming language). As you can see, interfaces are highly polymorphic. Consider the standard.net interface named ICloneable defined in the System namespace. This interface defines a single method named Clone(): public interface ICloneable object Clone(); If you examine the.net Framework 4.0 SDK documentation, you ll find that a large number of seemingly unrelated types (System.Array, System.Data.SqlClient.SqlConnection, System.OperatingSystem, System.String, etc.) all implement this interface. Although these types have no common parent (other than System.Object), we can treat them polymorphically via the ICloneable interface type. For example, if you had a method named CloneMe() that took an ICloneable interface parameter, you could pass this method any object that implements said interface. Consider the following simple Program class defined within a Console Application named ICloneableExample: class Program static void Main(string[] args) Console.WriteLine("***** A First Look at Interfaces *****\n"); // All of these classes support the ICloneable interface. string mystr = "Hello"; OperatingSystem unixos = new OperatingSystem(PlatformID.Unix, new Version()); System.Data.SqlClient.SqlConnection sqlcnn = new System.Data.SqlClient.SqlConnection(); // Therefore, they can all be passed into a method taking ICloneable. CloneMe(myStr); CloneMe(unixOS); CloneMe(sqlCnn); Console.ReadLine(); private static void CloneMe(ICloneable c) // Clone whatever we get and print out the name. object theclone = c.clone(); Console.WriteLine("Your clone is a: 0", theclone.gettype().name); When you run this application, the class name of each class prints out to the console, via the GetType() method you inherit from System.Object (Chapter 15 provides full coverage of this method and.net reflection services). Another limitation of traditional abstract base classes is that each derived type must contend with the set of abstract members and provide an implementation. To see this problem, recall the shapes hierarchy we defined in Chapter 6. Assume we defined a new abstract method in the Shape base class named GetNumberOfPoints(), which allows derived types to return the number of points required to render the shape: abstract class Shape... // Every derived class must now support this method! public abstract byte GetNumberOfPoints(); Clearly, the only type that has any points in the first place is Hexagon. However, with this update,

9 every derived class (Circle, Hexagon, and ThreeDCircle) must now provide a concrete implementation of this function even if it makes no sense to do so. 7) (a) What are Pointers? Is it possible to use pointers in C#? Explain [3] When you wish to work with pointers in C#, you must specifically declare a block of unsafe code using the unsafe keyword (any code that is not marked with the unsafe keyword is considered safe automatically). For example, the following Program class declares a scope of unsafe code within the safe Main() method: class Program static void Main(string[] args) unsafe // Work with pointer types here! // Can't work with pointers here! In addition to declaring a scope of unsafe code within a method, you can build structures, classes, type members, and parameters that are unsafe. // This entire structure is "unsafe" and can be used only in an unsafe context. public unsafe struct Node public int Value; public Node* Left; public Node* Right; (b) Explain the concept of delegates with example [7] A delegate is a type-safe object that points to another method in the application, which can be invoked at a later time.(i.e) contains the details of the method rather than data. * A delegate type maintains 3 pieces of information: * name of the method on which it makes calls. * arguments * return value * Once created, it may dynamically invoke the method it points at run time. * It can be used to hold reference to a method of any class. The only requirement is that its signature must match the signature of the method. Creating and using delegates invloves 4 steps 1) Delegate declaration 2) Delegate instantiation 3) Delegate methods definition 4) Delegate invocation A delegate defines a class using the class System.Delegate as a base class Delegate methods are any functions whose signature matches the delegate signature exactly. The delegate instance holds the reference to delegate methods(invoke the methods indirectly) Defining a Delegate: modifier delegate return-type delegate-name(parameters);

10 public delegate int binaryop(int x,int y); public class simplemath public static int add(int x,int y) return x+y; public static int sub(int x,int y) return x-y; class program static void Main() binaryop o=new binaryop(simplemath.add); binaryop a=new binaryop(simplemath.sub); Console.WriteLine( Sum is 0, o(10,10)); Console.WriteLine( Difference is 0, a(20,10)); MultiCast Delegates Also known as combinable delegates must satisfy the following conditions The return type of the delegate must be void None of the parameters of the delegate type can be declared as output parameters,using out keyword If D is a delegate that satisfies the above conditions and d1,d2,d3,d4 are instances of D, then the stmnts d3=d1+d2; // d3 refers to 2 methods d4=d3-d2; // d4 refers to only d1 method Are valid provided that the delegate instances d1 and d2 have already been initialized with method references and d3 and d4 contain null reference For a multicast delegate instance that was created by combining 2 delegates, the invocation list is formed by concatenating the invocation list of the two operands of the addition operation delegates are invoked in the order they are add delegate void A(); class DM Static public void display() C.WL( New delhi ); Static public void print() C.WL( New York ); class Mtest public static void Main() A m1= new A(DM.display); A m2= new A(DM.print); A m3= m1+m2; A m4= m2+m1; A m5= m3 - m2; m3(); m4(); m5();

11 8) What are events in C#? Write a C# program to explain how delegates are used for event handling [5] Events: * It is a delegate type class member that is used by the object or class to provide a notification to other objects that an event has occurred.events are declared using the simple event declaration format: modifier event type event-name; * type of an event declaration must be a delegate type * event is a keyword that signifies that the event name is an event Egpublic event EventHandler Click; public event RateChange Rate; using System; public delegate void A(string str) //delegation declaration first class Eventclass public event A status; // declaration of the event public void TriggerEvent() if(status!= null) status("event Triggered"); class EventTest public static void Main() Eventclass ec=new Eventclass(); EventTest et=new EventTest(); ec.status+= new A(et.Eventcatch); ec.triggerevent(); public void Eventcatch(string str) Console.WriteLine(str); *****************************

PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, September 2014

PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, September 2014 PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, September 2014 Topics in Enterprise Architectures-II Solution Set Faculty: Jeny Jijo 1) What is Encapsulation? Explain the two ways of enforcing

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

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

Getter and Setter Methods

Getter and Setter Methods Example 1 namespace ConsoleApplication14 public class Student public int ID; public string Name; public int Passmark = 50; class Program static void Main(string[] args) Student c1 = new Student(); Console.WriteLine("please..enter

More information

DC69 C# and.net JUN 2015

DC69 C# and.net JUN 2015 Solutions Q.2 a. What are the benefits of.net strategy advanced by Microsoft? (6) Microsoft has advanced the.net strategy in order to provide a number of benefits to developers and users. Some of the major

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

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

Framework Fundamentals

Framework Fundamentals Questions Framework Fundamentals 1. Which of the following are value types? (Choose all that apply.) A. Decimal B. String C. System.Drawing.Point D. Integer 2. Which is the correct declaration for a nullable

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

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

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

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

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

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

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

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

Increases Program Structure which results in greater reliability. Polymorphism

Increases Program Structure which results in greater reliability. Polymorphism UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the

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

Chapter 5. Inheritance

Chapter 5. Inheritance Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super

More information

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Islamic University of Gaza Faculty of Engineering Computer Engineering Department Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B

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

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

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

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

ENCAPSULATION AND POLYMORPHISM

ENCAPSULATION AND POLYMORPHISM MODULE 3 ENCAPSULATION AND POLYMORPHISM Objectives > After completing this lesson, you should be able to do the following: Use encapsulation in Java class design Model business problems using Java classes

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

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

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

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net Objective of the Course: (Why the course?) To provide a brief introduction to the.net platform and C# programming language constructs. Enlighten the students about object oriented programming, Exception

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

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

Test iz programskog jezika C# - ASP Izaberite tačan odgovor. Student's name : Programiranje ASP C# 1) A local variable

Test iz programskog jezika C# - ASP Izaberite tačan odgovor. Student's name :   Programiranje ASP C# 1) A local variable Student's name : E-mail: Test štampajte i skeniranog ga vratite na e-mail office@e-univerzitet.com U slučaju da nemate tehničke mogućnosti, prihvata se i da na datu e-mail adresu pošaljete odgovore sa

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

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

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Lecture 36: Cloning Last time: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting Today: 1. Project #7 assigned 2. equals reconsidered 3. Copying and cloning 4. Composition 11/27/2006

More information

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

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

More information

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

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

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 (OOP) Fundamental Principles of OOP

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

More information

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

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

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University (12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables

More information

PES INSTITUTE OF TECHNOLOGY

PES INSTITUTE OF TECHNOLOGY Seventh Semester B.E. IA Test-I, 2014 USN 1 P E I S PES INSTITUTE OF TECHNOLOGY C# solution set for T1 Answer any 5 of the Following Questions 1) What is.net? With a neat diagram explain the important

More information

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck C++ Crash Kurs Polymorphism Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ Polymorphism Major abstractions of C++ Data abstraction

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur School of Computing, 12/26/2012 1 VISUAL PROGRAMMING_IT0309 Semester Number 05 G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur UNIT 1 School of Computing, Department

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

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

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

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

Programming in C# Inheritance and Polymorphism

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

More information

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

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

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a

More information

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

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

More information

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

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

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? QUIZ Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed? Or Foo(x), depending on how we want the initialization

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 03: Creating Classes MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Creating Classes 2 Constructors and Object Initialization Static versus non-static fields/methods Encapsulation

More information

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani Object Oriented Programming C++ 6 th Sem, A Div 2018-19 Ms. Mouna M. Naravani Object Oriented Programming (OOP) removes some of the flaws encountered in POP. In OOPs, the primary focus is on data rather

More information

Brief Summary of Java

Brief Summary of Java Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 03: Creating Classes MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Constructors and Object Initialization Static versus non-static fields/methods Encapsulation

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

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

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

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

More information

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING Wednesady 23 rd March 2016 Afternoon Answer any FOUR questions out of SIX. All

More information

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

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Recitation 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University Project 5 Due Wed, Oct. 22 at 10 pm. All questions on the class newsgroup. Make use of lab

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

Get Unique study materials from

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

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

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

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

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

CHAPTER 5: EXCEPTION & OBJECT LIFETIME

CHAPTER 5: EXCEPTION & OBJECT LIFETIME CHAPTER 5: EXCEPTION & OBJECT LIFETIME ERRORS, BUGS & EXCEPTION Keywords Meaning Errors These are caused by end-user of the application. For e.g., entering un-expected value in a textbox, say USN. Bugs

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

Table of Contents Preface Bare Necessities... 17

Table of Contents Preface Bare Necessities... 17 Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17

More information

Programming in Java, 2e Sachin Malhotra Saurabh Choudhary

Programming in Java, 2e Sachin Malhotra Saurabh Choudhary Programming in Java, 2e Sachin Malhotra Saurabh Choudhary Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism

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

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Exam Paper CMPE212, WINTER TERM, 2016 FINAL EXAMINATION 9am to 12pm, 19 APRIL 2016 Instructor: Alan McLeod If the instructor is unavailable

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

Part III. Object-Oriented Programming with C#

Part III. Object-Oriented Programming with C# Part III Object-Oriented Programming with C# Chapter 5 Understanding Encapsulation In the Chapters 3 and 4, you investigated a number of core syntactical constructs that are commonplace to any.net application

More information

Student Guide Revision 1.0

Student Guide Revision 1.0 Robert J. Oberg Student Guide Revision 1.0 Object Innovations Course 411 C# Essentials Rev. 1.0 Student Guide Information in this document is subject to change without notice. Companies, names and data

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

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

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Chapter 4: Writing Classes

Chapter 4: Writing Classes Chapter 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Writing Classes We've been using predefined classes. Now we will learn to write our own

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 6 : Abstraction Lecture Contents 2 Abstract classes Abstract methods Case study: Polymorphic processing Sealed methods & classes

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

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

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

More information

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java. Classes Introduce to classes and objects in Java. Classes and Objects in Java Understand how some of the OO concepts learnt so far are supported in Java. Understand important features in Java classes.

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

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

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Digital Urban Visualization. People as Flows. 10.10.2016 ia zuend@arch.ethz.ch treyer@arch.ethz.ch chirkin@arch.ethz.ch Object Oriented Programming? Pertaining to a technique

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

Understanding Inheritance and Polymorphism

Understanding Inheritance and Polymorphism Chapter 6 Understanding Inheritance and Polymorphism Chapter 5 examined the first pillar of OOP: encapsulation. At that time, you learned how to build a single well-defined class type with constructors

More information

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

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

More information