CommerceClasses And Objects In C Sharp MCQs
Practice Classes And Objects In C Sharp MCQs for competitive exams.
Classes And Objects In C Sharp MCQs
Practice questions from this topic.
What will be the output of the following C# code? class maths { int i; public maths(int ii) { ii = -25; int g; g = ii > 0 ? ii : ii * -1; Console.WriteLine(g); } } class maths1 :maths { public maths1(int ll) :base(ll) { ll = -1000; Console.WriteLine((ll > 0 ? ll : ll * -1)); } } class Program { static void Main(string[] args) { maths1 p = new maths1(6); Console.ReadLine(); } }
- A. -25 -1000
- B. -1000 -25
- C. 25 1000
- D. None of the mentioned
Correct Answer: C
What will be the output of the following C# code? enum color:int { red, green, blue = 5, cyan, pink = 10, brown } console.writeline((int)color.green); console.writeline((int)color.brown);
- A. 2 10
- B. 2 11
- C. 1 11
- D. 1 5
Correct Answer: C
What will be the output of the following C# code? interface calc { void cal(int i); } public class maths :calc { public int x; public void cal(int i) { x = i * i; } } class Program { public static void Main(string[] args) { display arr = new display(); arr.x = 0; arr.cal(2); Console.WriteLine(arr.x); Console.ReadLine(); } }
- A. 0
- B. 2
- C. 4
- D. None of the mentioned
Correct Answer: C
Choose the wrong statement from the given set of statements?
- A. All operators in C#.NET cannot be overloaded
- B. We can use the new modifier to modify a nested type if the nested type is hiding another type
- C. Operator overloading permits the use of symbols to represent computations for a type
- D. In case of operator overloading all parameters must be of different type than the class or struct that declares the operators
Correct Answer: D
Which statements are correct about operator overloading?
- A. Mathematical or physical modeling where we use classes to represent objects such as vectors, matrices, complex-numbers etc
- B. Graphical programs where coordinate related objects are used to represent positions on the screen
- C. Financial programs where a class represents an amount of money
- D. All of the mentioned
Correct Answer: D
Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.
- A. Constructor
- B. Finalize()
- C. Destructor
- D. End
Correct Answer: C
Which of these is not a correct statement?
- A. A recursive method must have a base case
- B. Recursion always uses stack
- C. Recursion is always managed by C# Runtime environment
- D. Recursive methods are faster that programmer written loop to call the function repeatedly using a stack
Correct Answer: C
Which is the correct way to create an object of the given class abc?
- A. Declaring existing class as sealed
- B. Declaring existing class as override
- C. Declaring existing class as overloads
- D. Declaring existing class as shadows
Correct Answer: A
What will be the output of the following C# code? class A { public virtual void display() { Console.WriteLine("A"); } } class B: A { public override void display() { Console.WriteLine(" B "); } } class Program { static void Main(string[] args) { A obj1 = new A(); B obj2 = new B(); A r; r = obj1; r.display(); r = obj2; r.display(); Console.ReadLine(); } }
- A. A, A
- B. B, B
- C. Compile time error
- D. A, B
Correct Answer: D
Choose the correct statements about enum used in C#.NET?
- A. An enum variable cannot have a private access modifier
- B. An enum variable can be defined inside a class or a namespace
- C. An enum variable cannot have a protected access modifier
- D. An enum variable cannot have a public access modifier
Correct Answer: C
What does the following C# code imply? csharp abc; abc = new charp();
- A. Object creation on class csharp
- B. Create an object of type csharp on heap or on stack depending on the size of object
- C. create a reference c on csharp and an object of type csharp on heap
- D. create an object of type csharp on stack
Correct Answer: C
What will be the output of the following C# code? namespace ConsoleApplication4 { public abstract class A { public int i = 7; public abstract void display(); } class B: A { public int j; public override void display() { Console.WriteLine(i); Console.WriteLine(j); } } class Program { static void Main(string[] args) { B obj = new B(); A obj1 = new B(); obj.j = 1; obj1.i = 8; obj.display(); Console.ReadLine(); } } }
- A. 0, 8
- B. 1, 8
- C. 1, 7
- D. 7, 1
Correct Answer: D