2. OOP: Object oriented programming language is the language which deals with the objects and classes. a. Properties or features of OOP: i. Encapsulation: Encapsulation is wrapping of data into a single unit. In this the data is bound together inside a class which is hidden from outside world.
Eg: class X { Int i=5; Int j; }
ii. Inheritance: It is the process of creating a new class from the existing one. This new class is the child class which inherits all the characteristics of the parent class.
Eg: class X { public int a; Public int b; } Class Y:X { Public int a; Public int b; } Static void main() { Y o=new Y(); o.a=6; }
iii. Polymorphism: This is a process in which methods with same name performs different tasks. This can be implemented in three ways: a) Overloading : In this different methods with same method name performs different tasks based on different type of parameters.
Eg: class X { Public int add(int a, int b) { Return a+b; } Public int add(int a, int b, int c) { Return a*b*c; } } Static void main() { X o=new X(); Int i=o.add(2,3);------------o/p=5 Int j=o.add(4,5,6);----------o/p=120 }
b) Overriding: In this different methods with same signature performs differently in parent class and child class. Here the parent function in the child class is completely replaced by other function. When a class is overridden then we can declare an object of child class as parent type.
Eg: class X { Virtual Public void print() { Console.writeline("parent"); } } Class Y:X { Override public void print() { Console.writeline("child"); } } Static void main() { X o=new X(); o.print();---------------o/p=parent Y x=new Y(); x.print();---------------o/p=child X z=new Y(); z.print();----------------o/p=child }
c) Method hiding(shadowing): Is a process where the parent function is hidden in the child class using the keyword "new".
Eg: class X { Public void print() { Console.writeline("parent"); } } Class Y:X { New public void print() { Console.writeline("child"); } } Static void main() { X o=new X(); o.print();---------------o/p=parent Y x=new Y(); x.print();---------------o/p=child X z=new Y(); z.print();----------------o/p=parent }
|
| Author: http://venkattechnicalblog.blogspot.com/ 26 Apr 2008 | Member Level: Diamond Points : 0 |
Please format your contents.
Regards, Venkatesan Prabu . J
|