Keyword

Result: 265 questions

 Which of the following data structures can be used with the "in" operator to check if an item is in the data structure?

Quiz

Explain the features of C#?

Answer:

Below are some of the features supported in C# -

  • Constructors and Destructors
  • Properties
  • Passing Parameters
  • Arrays
  • Main
  • XML Documentation and
  • Indexers

 

View

What is the difference between “constant” and “readonly” variables in C#?

Answer:

  • “Const” keyword is used for making an entity constant. We cannot modify the value later in the code. Value assigning is mandatory to constant variables.
  • “readonly” variable value can be changed during runtime and value to readonly variables can be assigned in the constructor or at the time of declaration.
View

Explain Copy constructor in C#?

Answer:

If the constructor contains the same class in the constructor parameter then it is called as copy constructor.

class MyClass
{
 public string prop1, prop2;
 public MyClass(string a, string b)
 {
 prop1 = a;
 prop2 = b;
 }
 
 public MyClass(MyClass myobj) // Copy Constructor
 {
 prop1 = myobj.prop1;
 prop2 = myobj.prop2;
 }
}
View

Explain Static constructor in C#?

Answer:

If the constructor is declared as static then it will be invoked only once for all number of instances of a class. Static constructor will initialize the static fields of a class.

class MyClass
{
 public string prop1, prop2;
 public MyClass(string a, string b)
 {
 prop1 = a;
 prop2 = b;
 }

Static MyClass()
 {
 Console.WriteLine(“Static Constr Test”);
 }
 public MyClass(MyClass myobj) // Copy Constructor
 {
 prop1 = myobj.prop1;
 prop2 = myobj.prop2;
 }
}
View

Explain Indexers in C#?

Answer:

Indexers are used for allowing the classes to be indexed like arrays. Indexers will resemble the property structure but only difference is indexer’s accessors will take parameters. For example,

class MyCollection<T>
{
 private T[] myArr = new T[100];
 public T this[int t]
 {
 get
 {
 return myArr[t];
 }
 set
 {
 myArr[t] = value;
 }
 }
}
View

Explain Attributes in C#?

Answer:

  • Attributes are used to convey the info for runtime about the behavior of elements like – “methods”, “classes”, “enums” etc.
  • Attributes can be used to add metadata like – comments, classes, compiler instruction etc.
View

Explain Overloading in C# ?

Answer:

When methods are created with the same name, but with different signature its called overloading. For example, WriteLine method in console class is an example of overloading. In the first instance, it takes one variable. In the second instance, “WriteLine” method takes two variable.

Console.WriteLine(x);
Console.WriteLine("The message is {0}", Message);

Different types of overloading in C# are

  • Constructor overloading
  • Function overloading
  • Operator overloading
View

What is Constructor Overloading in C# .net ?

Answer:

In Constructor overloading, n number of constructors can be created for the same class. But the signatures of each constructor should vary. For example

public class Employee 
{
 public Employee() 
 { }
 public Employee(String Name) 
 { }
}
View

Explain Inheritance in C# ?

Answer:

In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects. In inheritance, there will be two classes - base class and derived classes. A class can inherit attributes and methods from existing class called base class or parent class. The class which inherits from a base class is called derived classes or child class. For more clarity on this topic, let us have a look at 2 classes shown below. Here Class Car is Base Class and Class Ford is derived class.

class Car
{
 public Car()
 {
  Console.WriteLine("Base Class Car");
 }

 public void DriveType()
 {
  Console.WriteLine("Right Hand Drive");
 }
}

class Ford : Car
{
 public Ford()
 {
  Console.WriteLine("Derived Class Ford");
 }

 public void Price()
 {
  Console.WriteLine("Ford Price : 100K $");
 }
}

When we execute following lines of code ,

Ford CarFord = new Ford();
CarFord.DriveType();
CarFord.Price();

Output Generated is as given below.

Base Class Car
Derived Class Ford
Right Hand Drive
Ford Price : 100K $

What this means is that, all the methods and attributes of Base Class car are available in Derived Class Ford. When an object of class Ford is created, constructors of the Base and Derived class get invoked. Even though there is no method called DriveType() in Class Ford, we are able to invoke the method because of inheriting Base Class methods to derived class.

View

What is a Constructor in C# ?

Answer:

Constructor is a special method that get invoked/called automatically, whenever an object of a given class gets instantiated. In our class car, constructor is defined as shown below

public Car()
{
 Console.WriteLine("Base Class Car");
}

When ever an instance of class car is created from the same class or its derived class(Except Few Scenarios), Constructor get called and sequence of code written in the constructor get executed.

interface Breaks
{
 void BreakType();
}

interface Wheels
{
 void WheelType();
}

class Ford : Breaks, Wheels
{
 public Ford()
 {
  Console.WriteLine("Derived Class Ford");
 }
 public void Price()
 {
  Console.WriteLine("Ford Price : 100K $");
 }
 public void BreakType()
 {
  Console.WriteLine("Power Break");
 }
 public void WheelType()
 {
  Console.WriteLine("Bridgestone");
 }
}
View

What is a Destructor in C# ? 

Answer:

Destructor is a special method that get invoked/called automatically whenever an object of a given class gets destroyed. Main idea behind using destructor is to free the memory used by the object.

View

What is the prototype of the default constructor?

public class Test { }
Quiz

Which two are valid constructors for Thread?

  1. Thread(Runnable r, String name)
  2. Thread()
  3. Thread(int priority)
  4. Thread(Runnable r, ThreadGroup g)
  5. Thread(Runnable r, int priority)
Quiz

Which three statements are true?

  1. The default constructor initialises method variables.
  2. The default constructor has the same access as its class.
  3. The default constructor invokes the no-arg constructor of the superclass.
  4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
  5. The compiler creates a default constructor only when there are no other constructors for the class.
Quiz

Which constructs an anonymous inner class instance?

Quiz

Which of the following statements is true?

  1. If assertions are compiled into a source file, and if no flags are included at runtime, assertions will execute by default.
  2. As of Java version 1.4, assertion statements are compiled by default.
  3. With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.
  4. When evaluating command-line arguments, the VM gives -ea flags precedence over -da flags.
Quiz

How to store heavy structured data in android?

Quiz

According to the C++11 standard, what is the output of this program?

#include <iostream>

struct A {
  A() { foo(); }
  virtual ~A() { foo(); }
  virtual void foo() { std::cout << "1"; }
  void bar() { foo(); }
};

struct B : public A {
  virtual void foo() { std::cout << "2"; }
};

int main() {
  B b;
  b.bar();
}

 

Quiz

What value gets printed by the program below?

struct Foo{
        int x:1;
        int y:2;
};

struct Foo obj;

obj.x = 5;

printf("%d\n", obj.x);
Quiz

© 2017 QuizBucket.org