Object Oriented Programming language(OOPS):- It is a methodology to write the program where we specify the code in form of classes and objects.
CLASS:-Class is a user defined data type. it is like a template. In c# variable are termed as instances of classes. which are the actual objects.
EX:-
Class classname
{
[variable declaration;]
[Method declaration;]
Here Class is a keyword and class name is valid c# identifier. Everything inside the square brackets is optional.It is also valid class definition.
EX:-
Class Empty
{
}
NOTE:- There are some similarities and difference between class & struct. we will discuss later.
OBJECT:- Object is run time entity which has different attribute to identify it uniquely.
EX:-
Here This is an example of creating an object of type Rectangle.
Rectangle rect1=new rectangle();
Rectangle rect1=new rectangle();
Here variable 'rect1' & rect2 is object of the rectangle class.
The Method Rectangle() is the default constructor of the class. we can create any number of objects of Rectangle class.
Basic Principle of oops:- There are main three core principles of any object oriented languages.
- ENCAPSULATION:- Encapsulation provides the ability to hide the internal details of an object from its users.The concept of encapsulation is also known as data hiding or information hiding. In c# , Encapsulation is implemented using the access modifier keywords.
- Public
- Private
- protected
- Internal
- Protected Internal
- POLYMORPHISM:- It is also concept of oops. It is ability to take more than one form. An operation may exhibit different behaviour in different situations. Ex:- An addition operation involving two numeric values will produce sum and the same addition operation will produce a string.If we pass parameter numeric value then method return sum(numeric value) and if we pass parameter String then same method is return string value .this called Polymorphism. You can understand the types of Polymorphism in More Details.....
- INHERITANCE:- One class can include the feature of another class by using the concept of inheritance.In c# a class can be inherit only from one class at a time.Whenever we create class that automatic inherit from System.Object class,till the time the class is not inherited from any other class.
using System;
namespace Inheritance
{
class Program
{
public static void Main()
{
employee obj2 = new employee();
obj2.display();
obj2.show();
Console.ReadLine();
}
}
public class cls
{
public void display()
{
Console.WriteLine("HELLO");
}
}
public class employee : cls
{
public void show()
{
Console.WriteLine("welcome");
}
}
}
NOTE:-Here we are calling cls class(base class) member by creating the object of employ class(child class).it is known as inheritance. Other elements of oops concepts:
Steps:- open console application in your visual studio First.
Now copy the code and paste program.cs file and run the application.
OUTPUT:-
For More:-
- Create setup file with Database
- Web Form Controls
- File Handling Real Application
- Host ASP.NET Application on Server Free
- Ado.Net Application
- Asp.net 4.0 coding models
- How to create dll file for .NET Application
- How to use check constraint in your application
- Structure and classes in c#
- How to solve sql server database problems
- How to understand event concepts in c#
- How to implement WCF service in asp.net
- How to implement multi threading in c#
- How implement Web Form controls in asp.net application
- How to save image in database and display in picture Box control using c#
- How to use secure login page in asp.net with example
- How to Add and verify Captcha image in 3 tier architecture in asp.net
- How to use virtual keyboard in asp.net for security purpose
- How to implement hashing concepts in asp.net
- Learn complete .Net Interview Questions and answers for job seekers
I hope this helpful for you
To Get the Latest Free Updates Subscribe
Please share this post with your friends if it is helpful for you.
Download Whole Attached file
DOWNLOAD
k
ReplyDeletein this .its been said like "Whenever we create class that automatic inherit from System.Object class,till the time the class is not inherited from any other class."
ReplyDeleteif i am not wrong, every class inherits from system.object class.
will there be any situation when one derived class don't have the features of the system.object class?
hi mini, you alreay know c# ,java,c++ does not support multiple inheritance.there are four types of inheritance
ReplyDelete1- Single inheritance
2- multilevel inheritance
3- hierarchical inheritance
4- multiple inhritance
here i have used single inheritance.in multilevel inheritance if any class inherited from other class then
we can again inherit child class from another classes.same as hierarchical inheritance.c# does not support multiple
inheritance.if any class inherit from other class then you can not inherited from other class.it means all three are
possible but multiple inheritance is not possible.
Hello Mr. RAMASHANKER VERMA,
DeleteIn C# inheritance is only of two types.
Remaining are the sub- categories of inheritance.
Why c# does not supports multiple inheritace give an example
ReplyDeleteHi friend !this is good question, In multiple inheritance one child class inherit the feature of two or more base classes.
ReplyDeletefirst i will give YOU real time example. suppose there are two people with same name(ramesh)lives in two different home.if one person (ram) is friend of both(ramesh).if any unknown person came and asked about ramesh to ram.Here ram will confuse because he knowS two person with same name. So he can give wrong address.this is problem of multiple inheritance.
Now according to programming language: if two base class(student,men) has same method name(show()) and these two classes are inheriting by the another child class (employee).
if we create the object of child class(employee),then another two base class (student ,men) will load automatically in memory. if we access the show() method through employee class object(emp).ex:emp.show();at that time compiler will confuse which show() method called,so it will give error that why c# not support multiple inheritance.i have given perfect example why c# does not support multiple inheritance ,which is given below:
see it:
using System;
namespace whynot_mutiple_inheritsnce
{
class Program
{
public class student
{
public void show()
{
Console.WriteLine("this is student class method");
}
}
public class men
{
public void show()
{
Console.WriteLine("this is men class method");
}
}
public class employee : men,student
{
public void dislpay()
{
Console.WriteLine("this is employee class method");
}
}
public static void Main(string[] args)
{
employee emp = new employee();
emp.show();
Console.ReadLine();
}
}
}
compiler confuse which class show() method will call.
To solve this problem we use interface.
Nice define an idea....
DeleteImpressive Example...
Deletei was expecting this kind of sample example on this.
DeleteAwesome example
DeleteHi Rama Shanker, hope you know that there c# basically folly two type of inheritance
Delete1> Class Base inheritance
2> Interface Base inheritance .
C# and JAVA only one support Class Base inheritance but multiple support Interface Base inheritance .
For Example
Class Or interface base inheritance ,
//Class
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Type { get; set; }
}
//interface
public interface IApprove {
bool Approved { get; set; }
// etc
}
//inheritance
public class Student : Person, IApprove {
}
You might also leave the class Approve as such, and have classes with a property of that type:
public class Student : Person {
Approve _approve = new Approve();
public Approve Approve {
get { return _approve; }
}
}
Or Second Example
// Class and multiple inheritance
public interface ISteerable { SteeringWheel wheel { get; set; } }
public interface IBrakable { BrakePedal brake { get; set; } }
public class Vehicle : ISteerable, IBrakable
{
public SteeringWheel wheel { get; set; }
public BrakePedal brake { get; set; }
public Vehicle() { wheel = new SteeringWheel(); brake = new BrakePedal(); }
}
Thanks
Manish Ranjan.
Nicely explained Suresh :)
DeleteExcellent Rama Shanker, u given perfect example... Thanks
ReplyDeleteHello Mr.Rama Shanker..i am looking for a windows form which uses the oop building blocks
ReplyDeleteyes, you can use oops concepts in windows form application.Any things which you can implement in console application ,you can implement in windows forms application also.
Deleter
DeleteSuperb..perfect example.
ReplyDeleteSuperb !! perfect example.
ReplyDeleteperfect examples.
ReplyDeletesir plese upload WPF meterials with real time examples now a days everybody are asking WPF sir.....please provide
ReplyDeletea soon as possible ......
ok cn reddy .............wait.....few days....
ReplyDeletei understood it..its a perfect example
ReplyDeletesir let me know what exact difference between Abstraction and Encapsulation also give me one real time example 4 that......i hv faced this qn in most of my interviews but they did'nt satisfy with my answer...kindly provide..thank u
ReplyDelete
DeleteEncapsulation :- Wrapping up of data and methods into a single unit is Encapsulation (e.g. Class)
Abstraction :- It is an act of representing only the essential things without including background details. (e.g. Interface)
Great example
Delete:-)