Sponsored Links

Interview Questions



INTERVIEW QUESTIONS MICROSOFT C# DETAILS

Question: Define abstraction,encapsulation,inheritance:with example.

Answer: Abstraction : Abstraction works by abstracting common parts of objects and merging them into a single abstract class. An abstract class is a parent class that allows inheritance but can never be instantiated. Abstract classes contain one or more abstract methods that do not have implementation. Abstract classes allow specialization of inherited classes.

Encapsulation :The details of how objects worked are hidden to the user of that object.Like RGB colors.We define RGB internally what happened how complex is it is hidden from us.

Inheritance :Inheritance is the process of creating new classes, called derived classes, from existing classes.The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.

Category C# Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.2) By 8895 users
Added on 12/1/2012
Views 71945
Rate it!

Question: Define abstraction,encapsulation,inheritance:with example.

Answer:

Abstraction : Abstraction works by abstracting common parts of objects and merging them into a single abstract class. An abstract class is a parent class that allows inheritance but can never be instantiated. Abstract classes contain one or more abstract methods that do not have implementation. Abstract classes allow specialization of inherited classes.

Encapsulation :The details of how objects worked are hidden to the user of that object.Like RGB colors.We define RGB internally what happened how complex is it is hidden from us.

Inheritance :Inheritance is the process of creating new classes, called derived classes, from existing classes.The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own. Source: CoolInterview.com

Answered by: KV | Date: 2/7/2008 | Contact KV Contact KV

Abstract classes and Interfaces both are used either for design reasons or Security reasons.Both are used when you want to force a protocol of behaviour or anything you wants to come into the system.Take an Example of shape,line,circle and rectangle.
Anyone who wants to become a shape can implement the IShape interface and come into the system, this can also be achieved using abstract class but in case of abstract class if some one derives a class from line class that also comes into the system forcefully.So there is a choice whether you want to force something or you wants to make it optional.If you want to force then use abstract class if you want to keep optional use Interfaces.

Abstract class and Interfaces both are basically the same but with one major difference.Abstract classes are used whenever you want to force a Inheritance hierarchy whereas in Interfaces this is optional.If anybody wants to come into the system then he has the choice of implementing the interface and thus comes into the system.Whereas if you use abstract class then the all the classes down the hierarchy comes into the system forcefully.

ENCAPSULATION

It’s data hiding or data abstraction. Private member variables of a class are encapsulated so that they can only be accessed by specific methods/properties. This will prevent data corruption.
E.g Abstract class

abstract class Abstract1
{
public Abstract1()
{
constructor logic here
}
}
public abstract void abmethod();
public static void Main()
{
myclass mycls = new myclass();
mycls.nonabmethod();
mycls.abmethod();
}
}

e.g Interface
using System;
namespace OOPs
{
/// <summary>
/// Summary description for Interface1.
/// </summary>
public class Interface1 : myinterface
{
public static void Main()
{
Interface1 inf1 = new Interface1();
inf1.callmethod();
}
public Interface1()
{
// TODO: Add constructor logic here
}
public void callmethod()
{
Console.WriteLine("callmethod implemented!");
}

}
interface myinterface
{
void callmethod();
}
}


Encapsulation:-
using system;
public class Employee
{
private string empname;
public string GetEmpname()
{
return empname;
}
// Mutator Method

public void SetEmpname( string tempname)
{
empname=tempname;
}
}
Like the above way we can protect the private data from the outside world. Here we use two separate methods to assign/access and get/retrieve the required data.
public static int Main(string[] args)
{
Employee e= new Employee()
e.SetEmpname("Prasad");
Console.WriteLine("The Department is :"+e.GetEmpname());
return 0;
} Source: CoolInterview.com

Answered by: prasad pophale | Date: 4/5/2008 | Contact prasad pophale Contact prasad pophale

Abstraction is the process of hiding unnecessary data .
Encapsulation is wrapping of methods and functions in to single unit.
Inheritance is building new class based on existing class. Source: CoolInterview.com

Answered by: sunitha | Date: 9/5/2008 | Contact sunitha Contact sunitha

The Process of hiding the irrelevent details and exposing the relevent details. Source: CoolInterview.com

Answered by: Sunitha.N | Date: 11/13/2009 | Contact Sunitha.N Contact Sunitha.N

if u define as a abstract class it cannot be intantiated by its own,it mush be inherited with other class it is called as abstract class

Encapsulation is hiding the internal details of methods is called encapsulation

inheritance is a child class use the all elements in parent class is called as inheritance in c# we declare inheritance as a (":") Source: CoolInterview.com

Answered by: rajeshkumarreddy challa | Date: 5/18/2010 | Contact rajeshkumarreddy challa Contact rajeshkumarreddy challa

Encapsulation: Hiding of unusual data from end-user is called encapsulation.

Abstraction: Display whatever end-user required is Abstraction.

Inheritance: Deriving a new class from an old class is called inheritance Source: CoolInterview.com

Answered by: TARUN KUMAR | Date: 6/4/2010 | Contact TARUN KUMAR Contact TARUN KUMAR

Answer should be complete in itself. Source: CoolInterview.com

Answered by: dharmendra kumar | Date: 8/3/2010 | Contact dharmendra kumar Contact dharmendra kumar

Encapsulation:...........
It means wrapping the data and function having the common properties in a single unit (called class).
eg.........
bread, rice,pulse,etc are the members of the food class

Abstraction:...........
It means hiding the unnecessary details from the end user.
eg.....
when we create a package and use it in another program.

Inherritance:..............
It means using the all properties of the parent class by the child class.
eg...........
food is a class and bread is its child class.

Source: CoolInterview.com

Answered by: ajay singh | Date: 8/3/2010 | Contact ajay singh Contact ajay singh


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
Define abstraction,encapsulation,inheritance:with example.
View Answer
What is mean "Death of Diamod"?
View Answer
what is the main difference between delegate and an event in c#?
View Answer
How to use HASH TABLE,ARRAYLIST in c# explain with example?
View Answer
Assemblies are of the following types:

View Answer
What is the difference between shadow and override

View Answer
What is the top .NET class that everything is derived from?

View Answer
C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

View Answer
When you inherit a protected class-level variable?Who is it available to?

View Answer
Does C# support multiple inheritance?

View Answer

How do you inherit from a class in C#?


View Answer
What is an abstract class?

View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All C# Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2024 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions