You are on page 1of 8

Question Bank For 2nd IA

Syllabus
Object-Oriented Programming with C#: Definition of the C# Class and objects, The

Pillars of OOP, The First Pillar: C#s Encapsulation Services, PseudoEncapsulation: Creating Read-Only Fields, The Second Pillar: C#s Inheritance Supports, The Third Pillar: C#s Polymorphic Support, Generating Class Definitions Using VisualStudio .NET. 5 Hrs. 5) Exceptions and Object Lifetime: Errors, Bugs, and Exceptions, The Role of .NET Exception Handling, The System. Exception Base Class, Throwing a Generic Exception, Catching Exception, CLR System-Level Exception (System. System Exception), Custom Application-Level Exception (System. Application Exception ), Handling Multiple Exceptions, The Finally Block, Understanding Object Lifetime,The Basics of Garbage Collection. Question Bank Part A: Objective Type Questions I ) 5 Marks Objective Questions 1. By default the class in C# is a) Public b) Private c) Protected d) Internal 2. Main method in C # is always static . True /False. 3. The odd man out of the following a) Encapsulation b) Abstraction c) Inheritance d) Polymorphism 4) Define a Class : Ans : Class is a custom user defined type (UDT) that is composed of data (attributes) and functions that act on this data (often called methods). 5.C# supports Method Overloading .True/False 6.Self Reference can be done in C# using the keyword : a) this b)while c) for d)none 7.Function overloading is an example for a)Polymorphism b) Encapsulation c) Inheritance d) None. 8) In order to access the private data one can use the following a) Accessor /Mutator b) Properties c) None d) Both a and b 9) Main() can be declared as private if you desire ---- T/F 10) Every executable C# application must contain a class defining a Main() method ,which is
used to signify the entry point of the application. T/F 11) M is obligatory as C# is case sensitive . True 12) Main may be static or public. True 13) In C# the new keyword is the defacto way to create an object instance. True 14) Which one of the following is a illegal way of creating an object in c#. a) Car c1; b) Car C1; c1 = new Car() c) car c1 = new car() d) none 15) C# object variables are actually reference to the object in memory, not the actual object itself . true 16) Every C# class is automatically endowed with a default constructor , which you are free

redefine if need be. True 17) Default constructors never take arguments .True 18) Beyond allocating a new class instance , the default constructors ensures that all member data is set to an appropriate default value . True 19) The .NET garbage collector frees the allocated memory automatically and therefore C# does not support a delete keyword . True 20) .NET runtime environment automatically destroys the objects you allocate. True 21) The default value of object is a) Null b) 0 c) Undefined d) None 22) The output of the following statement is public static int Main() { int x; Console.WriteLine(x); } ----------23) Identify the Wrong Statement of the following 1. Read(): is used to capture a single character from the input stream. 2. ReadLine(): allows you to receive information from the input stream up until the carriage return. 3. Write() : pumps text to the output stream with a carriage return. 4. WriteLine(): pumps a text string (including a carriage return) to the output stream.

24) What is the output of the following statement : Console.WriteLine({0}Number{0}Number{0},9); 25) Value based types which include all numerical data types(int, float ,etc) as well as enumerations and structures are allocated on the stack.True 26) With respect to Reference type which one of the following is false a. These are allocated on the garbage-collected heap. b. These entities stay in memory until the .NET garbage collector destroys them. c. By default assignment of reference types results in a new reference to the same object in memory. d. None 27) In C# every data type is ultimately derived from a common base class:System.Object 28) Which one of the following is not a core member 1.Equals() 2.GetHashCode() 3.GetType() 4.ToString() 5.Finalize() 6.MemberwiseClone() 29) Which of the following statements refers Boxing
a. b. c. d.

short s =25 object objShort =s; short anothershort = (short)objShort; none short s =25 object objShort =s; short anothershort = (short)objShort;

30)Which one of the following statement is BADBOXING


a. b. c.

d.

string str = (string) objshort

31) Match the Following C# Access Modifier public private protected internal protected internal Meaning in Life

Marks a method as accessible from an object instance or any subclass Marks a method as accessible only by the class that has defined the method . Marks a method as usable by the defining class, as well as any child class but is private as far as the outside world is concerned. Defines a method that is publicly accessible by all types in an assembly (but not from outside the assembly) Defines a method whose access is limited to the current assembly.

32) Match the Following Parameter Modifier (none) out ref Meaning in Life It is assumed to be an input parameter passed by value. Output parameters are assigned by the called member. The value is assigned by the caller but may be reassigned within the scope of the method call. It allows u to send in a variable number of parameters as a single parameter.

params

33) Which one of the following is the correct syntax for declaring arrays a) Type[ ] instance = new Type[size]; 34) Which one of the following is not a member of array class a) Binary Search() b) GetEnumerator() c) Reverse() d) Sort() e)None 35) Which one of the following is a illegal way of method overloading a) public int GetX(); , public float GetX(); b) public void Draw (int x, int y, int height ,int width); public void Draw(float x, float y, float height, float width); public void Draw(Point upperleft,Point bottomRight); public void Draw(Rect r); 36) Pick the odd one out of the following a) Encapsulation b) Inheritance c) Polymorphism c) Delegation d) None d) none

37) The is a inheritance is also known as a) Classical inheritance b) Containment

38) In C# encapsulation is enforced at the syntactic level using the public , private , protected and protected internal keywords. True 39) If an object user wishes to alter the sate of an object it does so indirectly using accessor (get) and mutuator(set) methods. True
40) Any attempt to make assignments to a field marked readonly results in a compiler error:

True
41) The const cannot be assigned a new type instance and it must be resolved at compile time.

True
42) The value of read-only static fields however may be computed at runtime and therefore may be assigned type instances as well as simply data types (int ,float ,string ,etc.). True 43) Inheritance is the aspect of OOP that facilitates code reuse. True 44) The basic idea behind the classical inheritance is that new classes may leverage (and extend ) the functionality of other classes. True 45) A child class cannot directly access private members defined by its parent class ( as inheritance preserves encapsulation). True 46) C# demands that a given class have exactly one direct base class. True 47) It is not possible to have a single type with two or more base classes. True 48) Inheritance can be prevented using Sealed Classes. True

49) Delegation is simply the act of adding members to the containing class that make use of the contained classes functionality. True 50)Match the following a. Bugs 1) User b. Errors 2) Programmer c) Exceptions 3) Runtime Anomalies 51) Which one of the following is not an atom of the .NET Exception Handling a. A type that represents the details of the exceptional circumstance b. A method that throws the exception to the caller. c. A block of code that will invoke the exception ready method. d. A block of code that will process (or catch ) the exception (should it occur) e. None 52)Match the Following
System.Exception property HelpLink InnerException Message Source StackTrace TargetSite Meaning in Life This property returns a URL to a help file describing the error in detail This read only property can be used to obtain information about the previous exceptions that caused the current exception. This read only property returns the textual description of a given error. The error message itself is set as a constructor parameter This property returns the name of the assembly that threw the exception. This read-only property contains a string that identifies the sequence of calls that triggered the exception. As you might guess , this property is very useful during debugging. This read only property returns a MethodBase type , which describes numerous details about the method that threw the exception (ToString() will identify the method by name).

53) The managed heap maintains a pointer (commonly referred to as the new object pointer) that identifies exactly where the next object will be placed on the heap itself. True 54) A root can fall into any of the following categories: References to global objects (while not allowed in C# , raw CIL does not permit allocation of global objects) References to static objects. References to local objects within a given method. References to object parameters passed into a method Any CPU register that references a local object.

Part B: II) 5 Marks 1. Design a C# class for storing the packets in a router buffer ,which is normally implemented as a
Queue .The packet is an object whose structure is as follows :<Packet_ID ,Host_IP_Addr,Dst_IP_Addr>.Your class should support printing of packet details and avoid storing of duplicating packets in the Queue by overloading ToString() and Equals().

2. Write a program to define a class vehicle and a class engine. Let the vehicle class contain engine. The engine should be started at the source and stopped after reaching the destination .Let the speed and the distance be read. The program should throw an exception when the vehicle tries to travel beyond destination.Develop the application in C#. 3. Write a program to define a class College BUS and a class BusEngine .Let the CollegeBus class contain BusEngine .The BusEngine sould be started at the SDMCET Campus and stoppe after reaching the destination (say HUBLI) .Let the speed and the distance be read.The Program should throw an exception when the CollegeBus tries to travel beyond destination or speed increase beyond 100 kmper hour. Develop the application in C#.

4. Create a Employee Class with members say fullaname, EmpID , CurrPAy with Appropriate
Constructors and Destructors .Write a driver program to create 4 employees and at each time of the creation of a new employee display the count of objects created with the help of constructor .Also destroy the objects with the help of destructor and Garbage Collector. At each time of the destruction display the number of objects destroyed and number of objects remaining. 5. Design the Employee class which s derived from Person class having common behaviour of the employees. The employees can exhibit different behaviours like C# Experts ,Java Expert or expert in both .Develop an application which accepts an employee array and counts the number of employee expert in C# ,Expert in java and experts in both.Make suitable assumptions

Part C: III) 10 Marks 1. Write a program to define a class called PDA and a classes called RADIO and CALCULATOR .Let
the PDA class contain RADIO class and the CALCULATOR Class. RADIO must capable to get connected to the following stations say 1.Dharwad 2.Delhi .In addition the program must throw the OutOfRangeFrequency exceptions whenever the object user tries to connect other frequency channel. CALCULATOR must capable to perform the rudimentary calculations say addition , subtraction , multiplication ,division ,modular division and square root. The program must capable to throw the exceptions say DivideByZeroException and Negative Number Exception .Write driver class which can perform the following tasks : 1.Creation of TWO objects to PDA class 2. One object Connects fmDharwad 3.The other objects Performs division of two numbers 4.Finds the Generation of objects. 2) Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class . Use floating point variables to represent the private data of the class .Provide a constructor that enables an object of this class to be initialized when it is declared .Provide a no argument constructor with default values in case no initializes are provided. Provide public methods for each of the following : Addition of two Complex Numbers .The real parts are added together and the imaginary parts are added together. Subtraction of two Complex Numbers .The real part of he right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. Printing of Complex numbers in the form (a,b) ,where a is the real part and b is the imaginary part. 3) Create class Savings Account .Use Static variable annual InterestRate to store the interest rate for all account holders .Each object of the class contains a private instance variable savingsBalance indicating

the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12;this interest should be added to savingsBalance .Provide a static method ModifyInterestRate that sets the annualInterestRate to a new value.Write driver program to test class SavingsAccount.Instantiate two savingsAccount objects ,saver1 and saver2 with balances of $2000.00 and $3000.00 repectively.Set anualInteestRate to 4% , then calculate the monthly interest and print the new balances for each of the savers .Then set the annualInterestRate to 5% and calculate the next months interest and print the new balances for each of the savers. 4) Design a Person Class and populate the class Add the following fields as members of the person class . Name : String ,DOB : DateTime,Address : String ,MaritalStatus : String . Create appropriate constructors and properties. Write a method CanMarry() to return true or false if a person can get married (people can get married over the age of 18 if they are not already married). Design a method that prints the objects details in the format : Scott lives in 21 NewYork city born on 12/12/1980, single ,20 years old and can marry. Modify the person class to contain an enumeration of the marital status called MaritalStatus containing values for (Single,Married ,Divorced or Windowed ). Modify the CanMarry() method and the constructor. Demonstrate this entire problem by creating some employees ,reading their details ,displaying their complete details ,etc 5) Create a class called Date with month ,day and year as a private data members. Create a constructor which confirms the proper value for month and call method checkDay to confirm proper value for day and a methodsay TodateString() to return date string as month/day/year.Create a class called Employee which encapsulates employees first name ,last name ,birth date and hire date(object of date class)Create a constructor which assigns the value for self members. Include a method say ToEmployeeString() to return the firstname-lastname-hiredate and birthdate.Write a driver program to create an object to employee and display the Emloyees internal

OR IV) 10 Marks 1.a)Define Class . What is Method Overloading ? Give example. b)Discuss with illustration the Three Pillars of OOP. c)Define Properties. Differentiate between Readonly and Writeonly Properties. 2a) Differentiate between Classical and Adhoc Polymorphism with example. b)Discuss with illustration how the Encapsulation can be enforced using Traditional Accessors /Mutators and Class Properties . c) Define Inheritance . Give Example. Discuss how the base class can be controlled using base . 3a) What are sealed class ? Discuss with example. b)What is Containment/Delegation . Illustrate with one programming example. c)Define Polymorphism . Explain how the Polymorphism can be enforced using abstract classes and abstract methods with one programming example. 4) a)Explain Versioning with example. 5) a) Define Errors ,Bugs and Exceptions. Discuss what is the role of .NET Exception Handling.

b) What are the atoms of .NET Exception Handling. c) Give the meaning of CoreMembers of the System.Exception Base Class. 6) a)Discuss the following with examples i) Throwing a Generic Exception ii) Catching Exception iii) Handling Multiple Exceptions iv) Generic Catch Statements v) Rethrowing Exceptions vi) Finally Block b) Define object in C# .Discuss how the reference types are allocated on the managed heap. c) What are roots? Give the different categories of the root. 7) a) Discuss the following with example i) Finalizing a type. ii) Overriding a Finalize Method. iii) Building an adhoc Distruction Method using IDisposable interface. b) What is Garbage Collection? Define Generations. c) Define System.GC type along with its members.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

You might also like