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

Size: px
Start display at page:

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

Transcription

1 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 encapsulation with suitable examples [10] The concept of encapsulation revolves around the notion that an object s internal data should not be directly accessible from an object instance. Rather, if the caller wants to alter the state of an object, the user does so indirectly using accessor (i.e., getter ) and mutator (i.e., setter ) methods. In C#, encapsulation is enforced at the syntactic level using the public, private, internal, and protected Encapsulation provides a way to preserve the integrity of an object s state data. Rather than defining public fields (which can easily foster data corruption), you should get in the habit of defining private data, which is indirectly manipulated using one of two main techniques: Define a pair of accessor (get) and mutator (set) methods. Define a.net property. class Employee // Field data. private string empname;... // Accessor (get method) public string GetName() return empname; // Mutator (set method) public void SetName(string name) // Do a check on incoming value // before making assignment. if (name.length > 15) Console.WriteLine("Error! Name must be less than 16 characters!"); else empname = name; This technique requires two uniquely named methods to operate on a single data point. To test your new methods, update your Main() method as follows: static void Main(string[] args) Console.WriteLine("***** Fun with Encapsulation *****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.givebonus(1000); emp.displaystats(); // Use the get/set methods to interact with the object's name. emp.setname("marv"); Console.WriteLine("Employee is named: 0", emp.getname()); Console.ReadLine();

2 Because of the code in your SetName() method, if you attempted to specify more than 15 characters (see below), you would find the hard-coded error message print to the console: static void Main(string[] args) Console.WriteLine("***** Fun with Encapsulation *****\n");... // Longer than 15 characters! Error will print to console. Employee emp2 = new Employee(); emp2.setname("xena the warrior princess"); Console.ReadLine(); So far so good. You have encapsulated the private empname field using two methods named GetName() and SetName(). If you were to further encapsulate the data in the Employee class, you would need to add various additional methods (GetID(), SetID(), GetCurrentPay(), SetCurrentPay() for example). Each of the mutator methods could have within it various lines of code to check for additional business rules. While this could certainly be done, the C# language has a useful alternative notation to encapsulate class data. (2)Define a.net property empname; private int empid; private float currpay; // Properties! public string Name get return empname; set if (value.length > 15) Console.WriteLine("Error! Name must be less than 16 characters!"); else empname = value; // We could add additional business rules to the sets of these properties, // however there is no need to do so for this example. public int ID get return empid; set empid = value; public float Pay get return currpay; set currpay = value;... A C# property is composed by defining a get scope (accessor) and set scope (mutator) directly within the property itself. Notice that the property specifies the type of data it is encapsulating by what appears to be a return value. Also take note that, unlike a method, properties do not make use of parentheses (not even empty parentheses) when being defined. Consider the commentary on your current ID property: // The 'int' represents the type of data this property encapsulates. // The data type must be identical to the related field (empid). public int ID // Note lack of parentheses.

3 get return empid; set empid = value; Within a set scope of a property, you use a token named value, which is used to represent the incoming value used to assign the property by the caller. This token is not a true C# keyword, but is what is known as a contextual keyword. When the token value is within the set scope of the property, it always represents the value being assigned by the caller, and it will always be the same underlying data type as the property itself. Thus, notice how the Name property can still test the range of the string as so: public string Name get return empname; set // Here, value is really a string. if (value.length > 15) Console.WriteLine("Error! Name must be less than 16 characters!"); else empname = value; Once you have these properties in place, it appears to the caller that it is getting and setting a public point of data; however, the correct get and set block is called behind the scenes to preserve encapsulation: static void Main(string[] args) Console.WriteLine("***** Fun with Encapsulation *****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.givebonus(1000); emp.displaystats(); // Set and get the Name property. emp.name = "Marv"; Console.WriteLine("Employee is named: 0", emp.name); Console.ReadLine(); 2. (a) Explain is-a and has-a relationships with respect to inheritance? [05] Inheritance: * Classical inheritance ( is-a relationship): * Single * Multilevel * Hierarchical inheritance 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;

4 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 [05] C# supplies another keyword, sealed, that prevents inheritance from occurring. When you mark a class as sealed, the compiler will not allow you to derive from this type. For example, assume you have decided that it makes no sense to further extend the MiniVan class: // The MiniVan class cannot be extended! sealed class MiniVan : Car If you (or a teammate) were to attempt to derive from this class, you would receive a compile-time error: // Error! Cannot extend // a class marked with the sealed keyword! class DeluxeMiniVan : MiniVan 3) What are Exceptions? List out the core members of system exception class. Give an example for throwing a generic exception [10] Programming with structured exception handling involves the use of 4 interrelated entities a. A class type that represents the details of the exception that occured b. A member that throws an instance of the exception class to the caller. c. A block of code on the callers side that invokes the exception-prone member d. A block of code on the callers side that will process (or catch) the exception should it occur. e. The C# programming language offers four keywords i. Try ii. Catch iii. Throw iv. 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. 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.

5 7) InnerException: This read-only property can be used to obtain information about the previous exception that caused the current exception to occur. The previous exceptions are recorded by passing them into the constructor of the most current exception. 4) Illustrate with example, the various methods for obtaining interface references [10] * Explicit Cast static void Main() circle c=new circle( xxx ); Ipointy p; try p=(ipointy)c; catch(invalidcastexception e) as Keyword: static void Main() Hexagon h=new Hexagon( xxx ); Ipointy ip=h as Ipointy; if(ip!=null) Console.WriteLine( Points: 0, ip.points); else Console.WriteLine( Not pointy ); is Keyword: Static void Main() shape[] s = new hexagon(),new circle(),new triangle(); for(int i=0;i<s.length;i++) if (s[i] is Ipointy) Console.WriteLine(((Ipointy)s[i]).points) Else 5) Illustrate with an example, how would you build custom exceptions [10] using System; class myownexception:applicationexception //private string messagedetails; public myownexception()

6 public myownexception(string msg):base(msg) //messagedetails=msg; /*public override string Message get return(messagedetails); */ class exc1 public static void Main() int x=5,y=100; try float z=(float)x/(float)y; if(z<0.1) throw new myownexception("number is too small"); //throw new myownexception(); catch(myownexception e) Console.WriteLine(e.Message); try y=y/(y-y); catch(exception e1) Console.WriteLine("Message: 0",e1.Message); 6) How can we build finalizable and disposable types in.net Garbage Collector() [10] The supreme base class of.net, System.Object, defines a virtual method named Finalize(). The default implementation of this method does nothing whatsoever: // System.Object public class Object... protected virtual void Finalize()

7 When you override Finalize() for your custom classes, you establish a specific location to perform any necessary cleanup logic for your type. Given that this member is defined as protected, it is not possible to directly call an object s Finalize() method from a class instance via the dot operator. Rather, the garbage collector will call an object s Finalize() method (if supported) before removing the object from memory. Of course, a call to Finalize() will (eventually) occur during a natural garbage collection or when you programmatically force a collection via GC.Collect().the role of the Finalize() method is to ensure that a.net object can clean up unmanaged resources when it is garbage-collected. Thus, if you are building a class that does not make use of unmanaged entities (by far the most common case), finalization is of little use. In fact, if at all possible, you should design your types to avoid supporting a Finalize() method for the very simple reason that finalization takes time.when you allocate an object onto the managed heap, the runtime automatically determines whether your object supports a custom Finalize() method. If so, the object is marked as finalizable, and a pointer to this object is stored on an internal queue named the finalization queue. The finalization queue is a table maintained by the garbage collector that points to each and every object that must be finalized before it is removed from the heap. When the garbage collector determines it is time to free an object from memory, it examines each entry on the finalization queue and copies the object off the heap to yet another managed structure termed the finalization reachable table (often abbreviated as freachable, and pronounced effreachable ). At this point, a separate thread is spawned to invoke the Finalize() method for each object on the freachable table at the next garbage collection. Given this, it will take at the very least two garbage collections to truly finalize an object. The bottom line is that while finalization of an object does ensure an object can clean up unmanaged resources, it is still nondeterministic in nature, and due to the extra behind-the-curtains processing, considerably slower. Building Disposable Objects As you have seen, finalizers can be used to release unmanaged resources when the garbage collector kicks in. However, given that many unmanaged objects are precious items (such as raw database or file handles), it may be valuable to release them as soon as possible instead of relying on a garbage collection to occur. As an alternative to overriding Finalize(), your class could implement the IDisposable interface, which defines a single method named Dispose(): public interface IDisposable void Dispose(); If you are new to interface-based programming, Chapter 9 will take you through the details. In a nutshell, an interface is a collection of abstract members a class or structure may support. When you do support the IDisposable interface, the assumption is that when the object user is finished using the object, the object user manually calls Dispose() before allowing the object reference to drop out of scope. In this way, an object can perform any necessary cleanup of unmanaged resources without incurring the hit of being placed on the finalization queue and without waiting for the garbage collector to trigger the class s finalization logic. To illustrate the use of this interface, create a new C# Console Application named SimpleDispose. Here is an updated MyResourceWrapper class that now implements IDisposable, rather than overriding System.Object.Finalize(): // Implementing IDisposable. class MyResourceWrapper : IDisposable // The object user should call this method // when they finish with the object. public void Dispose()

8 // Clean up unmanaged resources... // Dispose other contained disposable objects... // Just for a test. Console.WriteLine("***** In Dispose! *****"); 7) 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 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.

9 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, 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. 8) Illustrate the process of implementing existing.net interface by Enumerable types[10] C# supports a keyword named foreach that allows you to iterate over the contents of any array type: // Iterate over an array of items. int[] myarrayofints = 10, 20, 30, 40;

10 foreach(int i in myarrayofints) Console.WriteLine(i); While it may seem that only array types can make use of this construct, the truth of the matter is any type supporting a method named GetEnumerator() can be evaluated by the foreach construct public class Garage private Car[] cararray = new Car[4]; public Garage() // Fill with some Car objects upon startup. cararray[0] = new Car("Rusty", 30); cararray[1] = new Car("Clunker", 55); cararray[2] = new Car("Zippy", 30); cararray[3] = new Car("Fred", 30); public class Program static void Main(string[] args) Garage carlot = new Garage(); // Hand over each car in the collection? foreach (Car c in carlot) Console.WriteLine("0 is going 1 MPH", c.petname, c.currentspeed); Console.ReadLine(); //This interface informs the caller that the object's subitems can be enumerated. public interface IEnumerable IEnumerator GetEnumerator(); As you can see, the GetEnumerator() method returns a reference to yet another interface named System.Collections.IEnumerator. This interface provides the infrastructure to allow the caller to traverse the internal objects contained by the IEnumerable-compatible container: // This interface allows the caller to obtain a container's subitems. public interface IEnumerator bool MoveNext (); // Advance the internal position of the cursor. object Current get; // Get the current item (read-only property). void Reset (); // Reset the cursor before the first member.

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

PES INSTITUTE OF TECHNOLOGY (BSC) V MCA, Second IA Test, OCTOBER 2017 Programming Using C#.NET (13MCA53) Solution Set Faculty: Jeny Jijo 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

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

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

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

.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

UNIT 6: INTERFACES & COLLECTIONS

UNIT 6: INTERFACES & COLLECTIONS UNIT 6: INTERFACES & COLLECTIONS DEFINING INTERFACES An interface is a collection of abstract-methods that may be implemented by a given class (in other words, an interface expresses a behavior that a

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

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

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

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

Introduction To C#.NET

Introduction To C#.NET Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However

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

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

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

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

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com 70-483 MCSA Universal Windows Platform A Success Guide to Prepare- Programming in C# edusum.com Table of Contents Introduction to 70-483 Exam on Programming in C#... 2 Microsoft 70-483 Certification Details:...

More information

NOIDATUT E Leaning Platform

NOIDATUT E Leaning Platform NOIDATUT E Leaning Platform Dot Net Framework Lab Manual COMPUTER SCIENCE AND ENGINEERING Presented by: NOIDATUT Email : e-learn@noidatut.com www.noidatut.com C SHARP 1. Program to display Hello World

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

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 inside: PROGRAMMING McCluskey: Working with C# Classes & The Advanced Computing Systems Association & The System Administrators Guild working

More information

Item 18: Implement the Standard Dispose Pattern

Item 18: Implement the Standard Dispose Pattern Item 18: Implement the Standard Dispose Pattern 1 Item 18: Implement the Standard Dispose Pattern We ve discussed the importance of disposing of objects that hold unmanaged resources. Now it s time to

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

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

Learning to Program in Visual Basic 2005 Table of Contents

Learning to Program in Visual Basic 2005 Table of Contents Table of Contents INTRODUCTION...INTRO-1 Prerequisites...INTRO-2 Installing the Practice Files...INTRO-3 Software Requirements...INTRO-3 Installation...INTRO-3 Demonstration Applications...INTRO-3 About

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

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

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

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

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

Implementing Subprograms

Implementing Subprograms Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing

More information

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes Based on Introduction to Java Programming, Y. Daniel Liang, Brief Version, 10/E 1 Creating Classes and Objects Classes give us a way of defining custom data types and associating data with operations on

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

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

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

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

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

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

drawobject Circle draw

drawobject Circle draw 25 THE VISITOR PATTERN The Visitor pattern turns the tables on our object-oriented model and creates an external class to act on data in other classes. This is useful if there are a fair number of instances

More information

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Developing Microsoft.NET Applications for Windows (Visual Basic.NET) Course Number: 2555 Length: 1 Day(s) Certification Exam This course will help you prepare for the following Microsoft Certified Professional

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

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

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

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

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

C# Programming in the.net Framework

C# Programming in the.net Framework 50150B - Version: 2.1 04 May 2018 C# Programming in the.net Framework C# Programming in the.net Framework 50150B - Version: 2.1 6 days Course Description: This six-day instructor-led course provides students

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

Question And Answer.

Question And Answer. Q.1 What would be the output of the following program? using System; namespaceifta classdatatypes static void Main(string[] args) inti; Console.WriteLine("i is not used inthis program!"); A. i is not used

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

C#: framework overview and in-the-small features

C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Understanding Structured Exception Handling

Understanding Structured Exception Handling Chapter 7 Understanding Structured Exception Handling In this chapter, you will learn how to handle runtime anomalies in your C# code through the use of structured exception handling. Not only will you

More information

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 C++\CLI Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 Comparison of Object Models Standard C++ Object Model All objects share a rich memory model: Static, stack, and heap Rich object life-time

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

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

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

Applied object oriented programming. 4 th lecture

Applied object oriented programming. 4 th lecture Applied object oriented programming 4 th lecture Today Constructors in depth Class inheritance Interfaces Standard.NET interfaces IComparable IComparer IEquatable IEnumerable ICloneable (and cloning) Kahoot

More information

The C# Programming Language. Overview

The C# Programming Language. Overview The C# Programming Language Overview Microsoft's.NET Framework presents developers with unprecedented opportunities. From web applications to desktop and mobile platform applications - all can be built

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

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java.

DC69 C# &.NET JUNE C# is a simple, modern, object oriented language derived from C++ and Java. Q.2 a. What is C#? Discuss its features in brief. 1. C# is a simple, modern, object oriented language derived from C++ and Java. 2. It aims to combine the high productivity of Visual Basic and the raw

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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Short Notes of CS201

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

More information

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

2. The object-oriented paradigm!

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

More information

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

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

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

3. Basic Concepts. 3.1 Application Startup

3. Basic Concepts. 3.1 Application Startup 3.1 Application Startup An assembly that has an entry point is called an application. When an application runs, a new application domain is created. Several different instantiations of an application may

More information

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

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

More information

CS201 - Introduction to Programming Glossary By

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

More information

20 Most Important Java Programming Interview Questions. Powered by

20 Most Important Java Programming Interview Questions. Powered by 20 Most Important Java Programming Interview Questions Powered by 1. What's the difference between an interface and an abstract class? An abstract class is a class that is only partially implemented by

More information

1: Introduction to Object (1)

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

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

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

More information

Inside the Garbage Collector

Inside the Garbage Collector Inside the Garbage Collector Agenda Applications and Resources The Managed Heap Mark and Compact Generations Non-Memory Resources Finalization Hindering the GC Helping the GC 2 Applications and Resources

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

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

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

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

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017 OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading

More information

INTERNAL ASSESSMENT TEST 1 ANSWER KEY

INTERNAL ASSESSMENT TEST 1 ANSWER KEY INTERNAL ASSESSMENT TEST 1 ANSWER KEY Subject & Code: C# Programming and.net-101s761 Name of the faculty: Ms. Pragya Q.No Questions 1 a) What is an assembly? Explain each component of an assembly. Answers:-

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

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

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

Programming in Visual Basic with Microsoft Visual Studio 2010

Programming in Visual Basic with Microsoft Visual Studio 2010 Programming in Visual Basic with Microsoft Visual Studio 2010 Course 10550; 5 Days, Instructor-led Course Description This course teaches you Visual Basic language syntax, program structure, and implementation

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1 CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining

More information

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio Introduction XXV Part I: C# Fundamentals 1 Chapter 1: The.NET Framework 3 What s the.net Framework? 3 Common Language Runtime 3.NET Framework Class Library 4 Assemblies and the Microsoft Intermediate Language

More information

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1 OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software

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

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

Software Design and Analysis for Engineers

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

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic? What property of a C# array indicates its allocated size? a. Size b. Count c. Length What property of a C# array indicates its allocated size? a. Size b. Count c. Length What keyword in the base class

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

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

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

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

More information

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

PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore

PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore 560 100 Department of MCA COURSE INFORMATION SHEET Programming Using C#.NET (13MCA53) 1. GENERAL INFORMATION: Academic Year:

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)

More information

Lecture 10 OOP and VB.Net

Lecture 10 OOP and VB.Net Lecture 10 OOP and VB.Net Pillars of OOP Objects and Classes Encapsulation Inheritance Polymorphism Abstraction Classes A class is a template for an object. An object will have attributes and properties.

More information