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? interface i1 { void f1(); } interface i2 :i1 { void f2(); } public class maths :i2 { public void f2() { Console.WriteLine("fun2"); } public void f1() { Console.WriteLine("fun1"); } } class Program { static Void Main() { maths m = new maths(); m.f1(); m.f2(); } }
- A. fun2
- B. fun1
- C. fun1 fun2
- D. fun2 fun1
Correct Answer: C
What will be the Correct statement in the following C# code? interface abc { String FirstName { get; set; } String LastName { get; set; } void print(); void stock(); int fun(); }
- A. Functions should be declared inside an interface
- B. It is workable code
- C. Properties cannot be declared inside an interface
- D. None of the mentioned
Correct Answer: B
What does the following C# code signify? class a { } class b : a { variable declaration; method declaration; }
- A. Declaration of a base class
- B. Declaration of a subclass
- C. Declaration of base class & subclass and how subclass inherits the base class
- D. None of the mentioned
Correct Answer: C
Which of the following is the correct way of implementing an interface addition by class maths?
- A. class maths : addition {}
- B. class maths implements addition {}
- C. class maths imports addition {}
- D. none of the mentioned
Correct Answer: A
What will be the output of the following C# code? static void Main(string[] args) { int X = 6,Y = 2; X *= X / Y; Console.WriteLine(X); Console.ReadLine(); }
- A. 12
- B. 6
- C. 18
- D. Compile time error
Correct Answer: C
What will be the output of the following C# code? enum days:int { sunday = -3, monday, tuesday } Console.WriteLine((int)days.sunday); Console.WriteLine((int)days.monday); Console.WriteLine((int)days.tuesday);
- A. -3 0 1
- B. 0 1 2
- C. -3 -2 -1
- D. sunday monday tuesday
Correct Answer: C
What will be the output of the following C# code? class maths { static maths() { int s = 8; Console.WriteLine(s); } public maths(int f) { int h = 10; Console.WriteLine(h); } } class Program { static void Main(string[] args) { maths p = new maths(0); Console.ReadLine(); } }
- A. 10, 10
- B. 0, 10
- C. 8, 10
- D. 8, 8
Correct Answer: C
What will be the output of the following C# code? namespace ConsoleApplication4 { abstract class A { int i; public abstract void display(); } class B: A { public int j; public override void display() { Console.WriteLine(j); } } class Program { static void Main(string[] args) { B obj = new B(); obj.j = 2; obj.display(); Console.ReadLine(); } } }
- A. 0
- B. 2
- C. Compile time error
- D. 1
Correct Answer: B
Select the class visibility modifiers among the following:
- A. Private, protected, public, internal
- B. Private, protected, public, internal, protected internal
- C. Private, protected, public
- D. All of the mentioned
Correct Answer: B
Which of these can be used to fully abstract a class from its implementation?
- A. Objects
- B. Packages
- C. Interfaces
- D. None of the Mentioned
Correct Answer: C
Which statements among following are correct?
- A. We can derive a class from a base class even if source code of base class not available
- B. Multiple inheritance is different from multiple levels of inheritance
- C. It is legal to make objects of one class as members of another class
- D. All of the mentioned
Correct Answer: D
Which return statement correctly returns the output?
- A. public int cube(int x) { return (x + x); }
- B. public int cube(int x) return (x + x)
- C. public int cube(int x) { return x + x; }
- D. None of the mentioned
Correct Answer: A