Important and Basic OOPS Concept - Questions & Answers

Started by Kalyan, Sep 03, 2008, 02:51 PM

Previous topic - Next topic

Kalyan

Important and Basic OOPS Concept

What is the difference between Information Hiding and Encapsulation?

Generally Encapsulation is often referred to as information hiding. Though the two terms are often used interchangeably, Information Hiding is really the result of Encapsulation, not a synonym for it. Both are distinct concepts.

Encapsulation makes it possible to separate an object's implementation from its behavior - to restrict access to its internal data. This restriction allows certain details of an object's behavior to be hidden. It allows us to create a "black box" and protects an object's internal state from corruption by its user.

What is an Interface?

An interface is a contract & defines the requisite behavior of generalization of types.

An interface mandates a set of behavior, but not the implementation. Interface must be inherited. We can't create an instance of an interface.

An interface is an array of related function that must be implemented in derived type. Members of an interface are implicitly public & abstract.

An interface can inherit from another interface.

What is Sealed modifiers?

Sealed types cannot be inherited & are concrete.

Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members.

Sealed members are allowed in sealed and non-sealed classes.

What is Abstract Class?

Abstract class exists extensively for inheritance. We can't create an instance of an abstract class. Abstract type must be inherited.

Static, Value Types & interface doesn't support abstract modifiers.

Static members cannot be abstract. Classes with abstract member must also be abstract.

What is New modifiers?

The new modifiers hides a member of the base class. C# supports only hide by signature.

What is Virtual keyword?

This keyword indicates that a member can be overridden in a child class. It can be applied to methods, properties, indexes and events.

What is Inheritance?

It provides a convenient way to reuse existing fully tested code in different context thereby saving lot of coding.

Inheritance of classes in C# is always implementation Inheritance.

What is Static Method?

It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.
What is Static field?

To indicate that a field should only be stored once no matter how many instance of the class we create.
What is Class?

A Class is the generic definition of what an object is a template.

The keyword class in C# indicates that we are going to define a new class (type of object)

What is Object?

Object is anything that is identifiable as a single material item.

Can Struct be inherited?

No, Struct can't be inherited as this is implicitly sealed.

What is Virtual method?

Virtual Method has implementation & provide the derived class with the option to override it.

What is Abstract method?

Abstract method doesn't provide the implementation & forces the derived class to override the method.

What is Polymorphisms?

Polymorphism means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.

There are two types of Polymorphism.
Compile time: function or operator overloading
Runtime: Inheritence & virtual functions