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.
How many values does a function return?
- A. 0
- B. 2
- C. 1
- D. any number of values
Correct Answer: C
Which statements are correct?
- A. If a base class consists of a member function fun() and a derived class do not have any function with this name. An object of derived class can access fun()
- B. A class D can be derived from class C, which is derived from class B which in turn is derived from class A
- C. If a base class and a derived class each include a member function with same name, the member function of the derived class will be called by object of derived class
- D. All of the mentioned
Correct Answer: D
What will be the output of the following C# expression? int a+= (float) b/= (long)c.
- A. float
- B. int
- C. long
- D. none of the mentioned
Correct Answer: B
What will be the output of the following C# code? class z { public string name1; public string address; public void show() { Console.WriteLine("{0} is in city{1}", name1, " ", address); } } class Program { static void Main(string[] args) { z n = new z(); n.name1 = "harsh"; n.address = "new delhi"; n.show(); Console.ReadLine(); } }
- A. Syntax error
- B. {0} is in city{1} harsh new delhi
- C. harsh is in new delhi
- D. Run successfully prints nothing
Correct Answer: C
Which keyword is used to declare a base class method while performing overriding of base class methods?
- A. this
- B. virtual
- C. override
- D. extend
Correct Answer: B
What is the process of defining a method in terms of itself, that is a method that calls itself?
- A. Polymorphism
- B. Abstraction
- C. Encapsulation
- D. Recursion
Correct Answer: D
Which of the following functionality is facilitated by inheritance mechanism?
- A. Use the existing functionality of base class
- B. Override the existing functionality of base class
- C. Implements new functionality in derived class
- D. All of the mentioned
Correct Answer: D
Which of these keywords is used to refer to member of base class from a sub class?
- A. upper
- B. base
- C. this
- D. none of the mentioned
Correct Answer: B
What will be the output of the following C# code? static void Main(string[] args) { int x = 4 ,b = 2; x -= b/= x * b; Console.WriteLine(x + " " + b); Console.ReadLine(); }
- A. 4 2
- B. 0 4
- C. 4 0
- D. 2 2
Correct Answer: C
What will be the output of the following C# code? class maths { public int length; public int breadth; public maths(int x, int y) { length = x; breadth = y; Console.WriteLine(x + y); } public maths(double x, int y) { length = (int)x; breadth = y; Console.WriteLine(x * y); } } class Program { static void Main(string[] args) { maths m = new maths(20, 40); maths k = new maths(12.0, 12); Console.ReadLine(); } }
- A. 60, 24
- B. 60, 0
- C. 60, 144
- D. 60, 144.0
Correct Answer: C
The process of defining two or more methods within the same class that have same name but different parameters list?
- A. Method overloading
- B. Method overriding
- C. Encapsulation
- D. None of the mentioned
Correct Answer: A
What will be the output of the following C# code? namespace ConsoleApplication4 { abstract class A { public int i; public abstract void display(); } class B: A { public int j; public int sum; public override void display() { sum = i + j; Console.WriteLine(+i + "n" + +j); Console.WriteLine("sum is:" +sum); } } class Program { static void Main(string[] args) { A obj = new B(); obj.i = 2; B obj1 = new B(); obj1.j = 10; obj.display(); Console.ReadLine(); } } }
- A. 2, 10 12
- B. 0, 10 10
- C. 2, 0 2
- D. 0, 0 0
Correct Answer: C