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.
Access specifiers which can be used for an interface are?
- A. Public
- B. Protected
- C. Private
- D. All of the mentioned
Correct Answer: A
What will be the output of the following C# code? class A { public int i; protected int j; } class B : A { public int j; public void display() { base.j = 3; Console.WriteLine(i + " " + j); } } class Program { static void Main(string[] args) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); } }
- A. 2 1
- B. 1 0
- C. 0 2
- D. 1 2
Correct Answer: D
What is the return type of destructor?
- A. int
- B. void
- C. float
- D. none of the mentioned
Correct Answer: D
Wrong statement about enum used in C#.NET is?
- A. An enum can be declared inside a class
- B. An object cannot be assigned to an enum variable
- C. An enum can be declared outside a class
- D. An enum can have Single and Double values
Correct Answer: D
The process of defining a method in a subclass having same name & type signature as a method in its superclass is known as?
- A. Method overloading
- B. Method overriding
- C. Method hiding
- D. None of the mentioned
Correct Answer: B
What will be the Correct statement in the following C# code? class baseclass { int a; public baseclass(int a1) { a = a1; console.writeline(" a "); } class derivedclass : baseclass { public derivedclass (int a1) : base(a1) { console.writeline(" b "); } } class program { static void main(string[] args) { derivedclass d = new derivedclass(20); } } }
- A. Compile time error
- B. b a
- C. a b
- D. The program will work correctly if we replace base(a1) with base.baseclass(a1)
Correct Answer: C
What will be the output of the following C# code? static void Main(string[] args) { int i = 10; double d = 35.78; fun(i); fun(d); Console.ReadLine(); } static void fun(double d) { Console.WriteLine(d); }
- A. 35.78 10
- B. 10 35
- C. 10 35.78
- D. None of the mentioned
Correct Answer: C
The data members of a class by default are?
- A. protected, public
- B. private, public
- C. private
- D. public
Correct Answer: C
Correct way to overload +operator?
- A. public sample operator + (sample a, sample
- B. B. public abstract operator + (sample a,sample b) C. public static sample operator + (sample a, sample b) D. all of the mentioned
Correct Answer: D
Number of constructors a class can define is?
- A. 1
- B. 2
- C. Any number
- D. None of the mentioned
Correct Answer: C
What will be the output of the following C# code? static void Main(string[] args) { int a = 5; int s = 0, c = 0; Mul (a, ref s, ref c); Console.WriteLine(s + "t " +c); Console.ReadLine(); } static void Mul (int x, ref int ss, ref int cc) { ss = x * x; cc = x * x * x; }
- A. 125 25
- B. 25 125
- C. Compile time error
- D. 0 0
Correct Answer: B
If no access modifier for a class is specified, then class accessibility is defined as?
- A. public
- B. protected
- C. private
- D. internal
Correct Answer: C