Questions to .NET and Programming in C#

36 1.3K 5
Questions to .NET and Programming in C#

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Questions to .NET and Programming in C#

Questions to NET and Programming in C# Part 2: 101->235 101 interface intA: one, two,three{ } 102 103 104 105 106 107 108 109 110 Which of the following statements are true for the above code? a) one ,two ,three must be c) one, two, three can be classes classes or interfaces b) Above code will generate an d) one, two, three must be error as multiple values after interfaces the : is not allowed in C# If Parent is a base class and Child is its derived class then which of the following statements is not valid? a) Parent p1=new Child(); c) Parent p1=new Parent(); b) Child c1=new Child(); d) Child c1=new Parent(); Any class that contain one or more abstract methods must be declared as a) Interface c) Static d) Private b) Abstract Which of the following are correct statements for implementing an abstract class a) public abstract void class c) abstract public ClassA ClassA b) public abstract class ClassA Which of the following methods can be called as an “operation”? //'ClassA.methodA()' : virtual or abstract members cannot be private a) public void methodA(){} c) void methodA(); b) public void methodA{} d) public void methodA(); Abstract methods holds only: a) return type c) name of method b) return statements d) Parameters A can be thought as a mould of a class c) Interface a) abstract class b) Delegates d) static class Which of the following is a valid statement to implement class B in the class A a) class A implements B c) class A:B b) class A implements class B d) class B:A Properties provide the opportunity to protect a field in a class by reading and writing to it using accessors b) False a) True using System; public class Parent{ public virtual void Count(){ Console.WriteLine("100"); } }; public class Child:Parent { public override void Count(){ 10 Console.WriteLine("1000"); 11 } 12 public static void Main(){ 13 Parent p=new Child(); 14 p.Count(); 15 } } What will be the output of the above program? [0.5] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.0] [1.5] 114 What error does the following code generates when compiled? abstract class Class { public void getNumber(); } class ClassA:Class { } a) The name of base class used c) The class ClassA must is invalid declare as abstract as the class does not implements all the methods of abstract base class b) 'Class.getNumber()' must declare a body because it is not marked abstract 115 116 [1.5] abstract class Class [1.5] { private abstract void getNumber(); } class ClassA:Class {} What error does the following code generates when compiled? a) The name of base c) The class ClassA must class used is invalid declare as abstract as the class does not implements all the methods of abstract base class b) 'Class.getNumber()' d) The abstract member cannot must declare a body be private because it is marked abstract Which of the following statements are true? [1.5] a) A class inherits all c) When an interface method is mapped onto a virtual method interface in a class, it is possible for implementations derived classes to override the provided by its base virtual method classes b) Without explicitly re- d) An explicit interface member implementing, a implementations can be abstract derived class can alter the interface mappings it inherits from its base 117 118 classes using System; public class Parent { public virtual void Display(){ Console.WriteLine("100"); } } public class Child1:Parent { public override void Display(){ Console.WriteLine("1000"); }} public class Child2:Parent { public override void Display(){ Console.WriteLine("1000"); } public static void Main() { Child1 c1=new Child1(); Child2 c2=new Child2(); Parent p=c2; c1.Display(); p.Display(); }} What will be the output of above code when compile/run? a) The code will generate c) The output of the code will an error, as the object be: p is not properly 1000 instantiated 1000 b) The code will generate d) The output of the code will be: an error, as the object 1000 c2 is not properly 100 instantiated //chương trình dư dấu ngoặc -Ỉ kiểm tra mắt: bó tay using System; public class Parent { public virtual void Display(){ Console.WriteLine("100"); } } public class Child1:Parent { public override void Display(){ Console.WriteLine("1000"); } public void Display(int i){ Console.WriteLine("{0}",i); }} public static void Main() { Parent p =new Child1(); [2.0] [2.0] p.Display(); p.Display(90); 119 120 }} What will be the output of above code when compile/run? a) The code will generate c) The code will generate a an error, as the object compilation error, as parent p is not properly class does not have a instantiated display method with one argument b) The output of the code d) The output of the code will be: will be: 1000 1000 90 1000 Which of the following statements are true with respect to a [2.0] virtual method a) In a virtual method c) Because methods are invocation, the allowed to hide inherited compile-time type of methods, it is possible for a the instance for which class to contain only one the invocation takes virtual method with the place determines the same signature actual method implementation to invoke b) For every virtual method inherited by or declared in a class, there exists a most derived mplementation of the method with respect to that class What will be the output of the code below? [2.0] class Room{ public bool isEmpty(){ return (true); } } class StaffRoom: Room{ public new bool isEmpty(){ return false; } public static void Main() { Room R1 = new StaffRoom(); System.Console.WriteLine(R1.isEmpty()); } 121 122 } c) False a) True b) The code will not d) The code will not compile and compile and generate generate an error at line an error at line abstract class Class{ [2.0] public abstract void getNumber(); public abstract void getHeight(); public bool isEmpty(){return (true);} } abstract class ClassA:Class{ public abstract void getWidth(); } class ClassB:ClassA { } What changes should be done in the above code so that the code does not generate any error at compile time? a) Remove the abstract c) Add the abstract modifier for modifier for the the function Class.isEmpty() Class.getNumber(), Class.getHeight() methods b) Remove the abstract d) Implement the methods modifier for the class getNumber(),getHeight(), ClassA getWidth() in the class ClassB c) Add the abstract modifier for the class ClassB Which of the following statements are true with respect to [2.0] abstract functions? c) An overriding event a) Abstract event declaration can include a new declarations are only modifier permitted in abstract classes d) An abstract event declaration b) An overriding event specifies that the accessors of declaration must the event are virtual, but does specify the exact not provide an actual same accessibility implementation of the modifiers, type, and accessors name as the inherited event c) An overriding event declaration should not include the sealed 123 124 125 modifier class Room{ [2.5] int number=0; public bool isEmpty(){ return (number>0); } } class StaffRoom: Room{ int number=10; public new bool isEmpty(){ return (number>0); } public static void Main() { Room R1=new StaffRoom(); System.Console.WriteLine(R1.isEmpty()); StaffRoom R2=new StaffRoom(); System.Console.WriteLine(R2.isEmpty()); } } The output of above code will be: a) 0,10 d) False, True b) 10,0 e) The code will generate an error c) True, False Which of the following statements are correct? [2.5] a) Like a non-abstract c) An explicit interface member class, an abstract implementations can be class must provide abstract implementations of all members of the interfaces that are listed in the base class list b) An abstract class is d) An explicit interface member not permitted to map implementations are interface onto abstract permitted to call abstract methods methods interface IMethods [2.5] { void F(); void G(); } abstract class C: IMethods { void IMethods.F() { FF(); } void IMethods.G() { GG(); } protected abstract void FF(); protected abstract void GG(); } Consider the above code The non-abstract that derive from C will have to implement: a) F() c) GG() d) G() b) FF() 126 Using directives are provided to facilitate the use of namespaces b) False a) True 127 Namespaces are defined using _ statements c) System a) Using b) Class d) Namespace 128 Which of the following statements correctly declares a namespace? a) Namespace{ - } c) namespace Namespacename{ - } b) Namespacename{ d) public namespace - } Namespacename{ - } 129 The “using” alias directives can be used to pull out and bring into scope one component from a namespace b) False a) True 130 The _ namespace provides the classes and methods for manipulating arrays a) System.IO c) System.Array b) System.Arr d) Array 131 For multiple levels of organizations _ can be used a) Classes c) a namespace b) System namespace d) a nested namespaces 132 The namespace contains all code required to interact with the including the console output a) IO c) Class d) Namespace b) System 133 When a class is used inside its namespace, the _ of that class is used a) Qualified name c) Unqualified name b) Namespace name 134 _ keyword is used to import the classes of the namespace c) namespace a) using b) class d) import 135 The Syntax of a predefined Sort method is: a) Arraytosort.Sort() c) System.Array.Sort(Arraytosort) b) Arraytosort.Array.Sort() d) System.Array.Sort() [0.5] [0.5] [0.5] [0.5] [0.5] [1.0] [1.0] [1.0] [1.0] [1.0] 136 Classes in the Base Class Library are categorized into based [1.0] on their functionality a) Assemblies c) Application b) Directives d) Namespaces 137 The syntax for declaring array is: a) arrayname DataType[]; b) arrayname[] DataType; 138 139 140 141 namespace space1{ } namespace space2{ } What does the above code implement: a) Nested namespaces c) d) c) c) delegates namespace Space1{ namespace Space2{ class MyClass{ } }} The fully qualified name of class MyClass is : a) Space1.MyClass() c) b) d) Space2.MyClass() DataType arrayname[]; DataType[] arrayname; [1.5] b) Multi level namespaces Within the namespace we can declare following: a) Class d) b) Another namespace e) Hierarchical namespaces [1.5] Interface All the mentioned options [1.5] Space1.Space2.MyCl ass() Space2.Space1.MyCla ss() namespace College.Library{ namespace Shelf{ class Book{ } } } The fully qualified name of class Book is: a) Shelf.Book() 142 [1.0] b) College.Library.Book() class Test{ static void Main() { int[] Array1= {3,2,1}; int i=Array.IndexOf(Array1,3); Console.WriteLine(i); [1.5] c) d) College.Library.Shelf Book() Library.Shelf.Book() [1.5] 143 144 145 146 147 148 } } What will be the output of above code a) b) class Question{ static void Main() { int[] List= {30,20,10}; Array.IndexOf(List,30); } } What will be the output of above code a) c) d) [1.5] c) The code will generate a compile time error d) contains classes useful for [1.5] b) The _ namespace synchronization a) System c) System.Thread b) System.Threading d) System.Synchronize When the array is initialized at the same time they are created, the c# compiler determines the size of array using a) the default array size for each data type c) the number of items in the initialization list b) the compilers presetting for each data d) The number present type array in the square bracket next to the data type at the right hand side By default the compiler opens _assembly a) mscorlib.dll c) system.dll b) Cdefault.dll d) namespace.dll Which of the following statements are true? a) An array is a data structure that d) The element type of an array can be any type, contains a number of variables, which but not an array type are accessed through computed indices b) The dimension lengths are not part of e) At run-time, a value the type of the array, but rather are of an array type is established when an instance of the null or a reference to array type is created at run-time an instance of that array type c) The elements of the array are all of the different types Which of the following statements are true with respect to an Array type a) System Array is itself an array-type d) An implicit reference [1.5] [2.0] [2.0] [2.0] ... System.Console.WriteLine(p); } public static void Main(){ string s= "Programming in c#" ; char[] separator={'' ''}; string[] words=s.Split(separator); 10 Print(words); 11 } } a) The code will generate an error at line... opportunity to protect a field in a class by reading and writing to it using accessors b) False a) True using System; public class Parent{ public virtual void Count(){ Console.WriteLine("100");... successfully and reference output the following text: In Try In Finally b) The code will compile successfully d) The code will and output the following text: compile successfully In Try and output

Ngày đăng: 29/08/2012, 16:37

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan