c question bank for 2 ndia

Upload: asad-ahmed

Post on 05-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 c Question Bank for 2 Ndia

    1/8

    Question Bank For 2 nd IASyllabusObject-Oriented Programming with C#: Definition of the C# Class and objects, ThePillars of OOP, The First Pillar: C#s Encapsulation Services, PseudoEncapsulation:Creating Read-Only Fields, The Second Pillar: C#s Inheritance Supports, The ThirdPillar: C#s Polymorphic Support, Generating Class Definitions Using VisualStudio.NET. 5 Hrs.5) Exceptions and Object Lifetime: Errors, Bugs, and Exceptions, The Role of .NETException Handling, The System. Exception Base Class, Throwing a GenericException, Catching Exception, CLR System-Level Exception (System. SystemException), Custom Application-Level Exception (System. ApplicationException ), Handling Multiple Exceptions, The Finally Block, Understanding ObjectLifetime,The Basics of Garbage Collection.

    Question Bank

    Part A: Objective Type QuestionsI ) 5 Marks Objective Questions1. By default the class in C# is

    a) Public b) Private c) Protected d) Internal2. Main method in C # is always static . True /False.3 . The odd man out of the following

    a) Encapsulation b) Abstraction c) Inheritance d) Polymorphism4) 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)none7. 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 b9) Main() can be declared as private if you desire ---- T /F10) Every executable C# application must contain a class defining a Main() method ,which isused to signify the entry point of the application. T/F11 ) M is obligatory as C# is case sensitive . True

    12) Main may be static or public. True13) In C# the new keyword is the defacto way to create an object instance. True14) 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 objectitself . true

    16) Every C# class is automatically endowed with a default constructor , which you are free

  • 7/31/2019 c Question Bank for 2 Ndia

    2/8

    redefine if need be. True 17) Default constructors never take arguments . True18) Beyond allocating a new class instance , the default constructors ensures that all member data is set to an appropriate default value . True19) The .NET garbage collector frees the allocated memory automatically and therefore C#does not support a delete keyword . True20) .NET runtime environment automatically destroys the objects you allocate. True21) The default value of object is a) Null b) 0 c) Undefine d d) None22) 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 asenumerations and structures are allocated on the stack. True

    26) With respect to Reference type which one of the following is falsea. 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.Object28) 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 Boxinga. short s =25

    b. object objShort =s;c. short anothershort = (short)objShort;d. none

    30) Which one of the following statement is BADBOXINGa. short s =25

    b. object objShort =s;c. short anothershort = (short)objShort;

  • 7/31/2019 c Question Bank for 2 Ndia

    3/8

    d. string str = (string) objshort

    31) Match the Following

    C# AccessModifier

    Meaning in Life

    public Marks a method as accessible from an object instance or any subclass

    private Marks a method as accessible only by the class that has defined the method

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

    internal Defines a method that is publicly accessible by all types in an assembly (butnot from outside the assembly)

    protectedinternal

    Defines a method whose access is limited to the current assembly.

    32) Match the Following

    Parameter Modifier

    Meaning in Life

    (none) It is assumed to be an input parameter passed by value.

    out Output parameters are assigned by thecalled member.

    ref The value is assigned by the caller but maybe reassigned within the scope of themethod call.

    params It allows u to send in a variable number of parameters as a single parameter.

  • 7/31/2019 c Question Bank for 2 Ndia

    4/8

    33) Which one of the following is the correct syntax for declaring arraysa) Type[ ] instance = new Type[size];

    34) Which one of the following is not a member of array classa) 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 followinga) Encapsulation b) Inheritance c) Polymorphism d) None

    37) The is a inheritance is also known asa) Classical inheritance b) Containment c) Delegation d) none

    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. True40) Any attempt to make assignments to a field marked readonly results in a compiler error:True41) The const cannot be assigned a new type instance and it must be resolved at compile time.True42) The value of read-only static fields however may be computed at runtime and therefore maybe assigned type instances as well as simply data types (int ,float ,string ,etc.). True43) Inheritance is the aspect of OOP that facilitates code reuse. True44) The basic idea behind the classical inheritance is that new classes may leverage (andextend ) the functionality of other classes. True45) A child class cannot directly access private members defined by its parent class ( asinheritance preserves encapsulation). True46) C# demands that a given class have exactly one direct base class. True47) It is not possible to have a single type with two or more base classes. True48) Inheritance can be prevented using Sealed Classes. True

  • 7/31/2019 c Question Bank for 2 Ndia

    5/8

    49) Delegation is simply the act of adding members to the containing class that make use of thecontained classes functionality. True50) Match the followinga. 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 Handlinga. 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.Exceptionproperty

    Meaning in Life

    HelpLink This property returns a URL to a help file describing the error in detail

    InnerException This read only property can be used to obtain information about the previous exceptions thatcaused the current exception.

    Message This read only property returns the textual description of a given error. The error message itself is set as a constructor parameter

    Source This property returns the name of the assembly that threw the exception.

    StackTrace This read-only property contains a string that identifies the sequence of calls that triggered theexception. As you might guess , this property is very useful during debugging.

    TargetSite This read only property returns a MethodBase type , which describes numerous details about themethod 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. True54) A root can fall into any of the following categories:

    References to global objects (while not allowed in C# , raw CIL does not permitallocation 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 Marks1. Design a C# class for storing the packets in a router buffer ,which is normally implemented as aQueue .The packet is an object whose structure is as follows :.Your class should support printing of packet details and avoid storing of duplicating packets in the Queue by overloading ToString() and Equals().

  • 7/31/2019 c Question Bank for 2 Ndia

    6/8

    2. Write a program to define a class vehicle and a class engine. Let the vehicle class contain engine. Theengine should be started at the source and stopped after reaching the destination .Let the speed and thedistance be read. The program should throw an exception when the vehicle tries to travel beyonddestination.Develop the application in C#.3. Write a program to define a class College BUS and a class BusEngine .Let the CollegeBus classcontain BusEngine .The BusEngine sould be started at the SDMCET Campus and stoppe after reachingthe destination (say HUBLI) .Let the speed and the distance be read.The Program should throw anexception 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 AppropriateConstructors and Destructors .Write a driver program to create 4 employees and at each time of thecreation of a new employee display the count of objects created with the help of constructor .Alsodestroy the objects with the help of destructor and Garbage Collector. At each time of the destructiondisplay 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 theemployees. 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 expertin C# ,Expert in java and experts in both.Make suitable assumptions

    Part C:

    III) 10 Marks1. Write a program to define a class called PDA and a classes called RADIO and CALCULATOR .Letthe PDA class contain RADIO class and the CALCULATOR Class. RADIO must capable to getconnected to the following stations say 1.Dharwad 2.Delhi .In addition the program must throw theOutOfRangeFrequency 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 theexceptions say DivideByZeroException and Negative Number Exception .Write driver class which can

    perform the following tasks :1.Creation of TWO objects to PDA class2. One object Connects fmDharwad3.The other objects Performs division of two numbers4.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 .Providea 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 subtractedfrom the real part of the left operand and the imaginary part of the right operand issubtracted 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 theimaginary part.

    3) Create class Savings Account .Use Static variable annual InterestRate to store the interest rate for allaccount holders .Each object of the class contains a private instance variable savingsBalance indicating

  • 7/31/2019 c Question Bank for 2 Ndia

    7/8

    the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate themonthly interest by multiplying the savingsBalance by annualInterestRate divided by 12;this interestshould be added to savingsBalance .Provide a static method ModifyInterestRate that sets theannualInterestRate to a new value.Write driver program to test class SavingsAccount.Instantiate twosavingsAccount objects ,saver1 and saver2 with balances of $2000.00 and $3000.00 repectively.SetanualInteestRate to 4% , then calculate the monthly interest and print the new balances for each of thesavers .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 ,etc5) 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 dayand a methodsay TodateString() to return date string as month/day/year.Create a class called Employeewhich encapsulates employees first name ,last name ,birth date and hire date(object of date class)Create aconstructor which assigns the value for self members. Include a method say ToEmployeeString() to returnthe firstname-lastname-hiredate and birthdate.Write a driver program to create an object to employee anddisplay the Emloyees internal

    ORIV) 10 Marks1.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 classesand 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.

  • 7/31/2019 c Question Bank for 2 Ndia

    8/8

    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 examplesi) Throwing a Generic Exception

    ii) Catching Exceptioniii) Handling Multiple Exceptionsiv) Generic Catch Statementsv) 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.

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@