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.
Can the method add() be overloaded in the following ways in C#? public int add() { } public float add(){ }
- A. True
- B. False
Correct Answer: B
What will be the output of the following C# code? public static void Main(string[] args) { p(); void p() { Console.WriteLine("hi"); } }
- A. Compile time error
- B. hi
- C. hi infinite times
- D. None of the mentioned
Correct Answer: A
Which keyword is used for correct implementation of an interface in C#.NET?
- A. interface
- B. Interface
- C. intf
- D. Intf
Correct Answer: A
What is the return type of constructors?
- A. int
- B. float
- C. void
- D. none of the mentioned
Correct Answer: D
The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code? class sample { int i = 10; int j = 20; public void display() { Console.WriteLine("base method "); } } class sample1 : sample { public int s = 30; } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s); obj.display(); Console.ReadLine(); } }
- A. 10, 20, 30 base method
- B. 10, 20, 0
- C. compile time error
- D. base method
Correct Answer: C
Select the sequence of execution of function f1(), f2() & f3() in C# .NET CODE? class base { public void f1() {} public virtual void f2() {} public virtual void f3() {} } class derived :base { new public void f1() {} public override void f2() {} public new void f3() {} } class Program { static void Main(string[] args) { baseclass b = new derived(); b.f1 (); b.f2 (); b.f3 (); } }
- A. f1() of derived class get executed f2() of derived class get executed f3() of base class get executed
- B. f1() of base class get executed f2() of derived class get executed f3() of base class get executed
- C. f1() of base class get executed f2() of derived class get executed f3() of derived class get executed
- D. f1() of derived class get executed f2() of base class get executed f3() of base class get executed
Correct Answer: B
Correct way of declaration of object of the following class is? class name
- A. name n = new name()
- B. n = name()
- C. name n = name()
- D. n = new name()
Correct Answer: A
Wrong statement about inheritance in C# .NET?
- A. In inheritance chain, object construction begins from base class towards derived class
- B. Inheritance cannot extend base class functionality
- C. A derived class object contains all base class data
- D. All of the mentioned
Correct Answer: B
What will be the output of the following C# code? class box { public int volume; int width; int height; int length; public box ( int w, int h, int l) { this.width = w; this.height = h; this.length = l; } ~ box() { volume = this.width * this.length * this.height; console.writeline(volume); } } class Program { public static void Main(string[] args) { box b = new box(4, 5, 9); Console.ReadLine(); } }
- A. 0
- B. Code executes successfully but prints nothing
- C. Compile time error
- D. 180
Correct Answer: D
The modifier used to hide the base class methods is?
- A. Virtual
- B. New
- C. Override
- D. Sealed
Correct Answer: B
Select correct differences between '=' and '==' in C#.
- A. '==' operator is used to assign values from one variable to another variable ''=' operator is used to compare value between two variables
- B. '=' operator is used to assign values from one variable to another variable '==' operator is used to compare value between two variables
- C. No difference between both operators
- D. None of the mentioned
Correct Answer: B
What will be the output of the following C# code? interface calc { void cal(int i); } class displayA :calc { public int x; public void cal(int i) { x = i * i; } } class displayB :calc { public int x; public void cal(int i) { x = i / i; } } class Program { public static void Main(string[] args) { displayA arr1 = new displayA(); displayB arr2 = new displayB(); arr1.x = 0; arr2.x = 0; arr1.cal(2); arr2.cal(2); Console.WriteLine(arr1.x + " " + arr2.x); Console.ReadLine(); } }
- A. 0 0
- B. 2 2
- C. 4 1
- D. 1 4
Correct Answer: C