Friday, 7 April 2017

Object Oriented Programming Structure - Features

Object Oriented Programming Structure (OOPS) – total – 12 marks
Theory – 2/12  marks
1)      What is Data Hiding?

Data hiding is the OOPS(Object Oriented Programming Structure) concept that enables data to be hidden from the outside world i.e. the main() function. By default , a  class is private and all the private members cannot be accessed by the object of the class. It can only be accessed indirectly through its member functions. In this sense, data is hidden.
There is no possibility that someone maintaining the code may inadvertently point to or otherwise access the wrong data unintentionally. Thus, all data not required by an object can be said to be "hidden."

Eg:
class sample
{
 int x;           // data hidden
 float y;   // data hidden
 public:
 void enter()
 {
  cin>>x>>y;
 }
 void display()
 {
  cout<<x<<y;
}};
 void main()
 { sample s;
   s.enter();  //x and y accessed indirectly through public member function enter()
 }

2)      What is data abstraction
Data abstraction is the act of representing only essential features and hiding background details.
For eg, we know the operation of a Television, but we may not know the internal hardware structure and the working of Television.


C++ example:
class sample
{
 int x;           // data abstraction
 float y;   // These details are completely abstracted from the class to the outside world
 public:
 void enter()
 {
  cin>>x>>y;
 }
 void display()
 {
  cout<<x<<y;
}};
 void main()
 { sample s;
   s.enter();  //object s accesses enter(), without knowing the details of x and y
 }


3)      What is an entity?
A thing with physical and independent existence. In C++ , it is termed as an instance of a class or an object.

4)      What are properties and behavior of the class?
The properties are the attributes of the class i.e. data members
The member functions are the behavior of the class.

5)      What is a class?
A class is a user-defined data type that contains within itself data members and member functions together called as members i.e. a class binds the data that describes an entity and functions together.

6)      What is meant by instantiation? Why is the object called instance of the class?
Instantiation is the process of a variable being constructed by the subroutines of the class.


7)      What is an object?
An object is an instance of a class. A class’s functions may be implemented only by way of the object.

Example of class and object
class sample
{
 int x;
 float y;
 public:
 void enter()
 {
  cin>>x>>y;
 }
 void display()
 {
  cout<<x<<y;
}};
 void main()
 { sample s;
   s.enter();
 }

8)      What is encapsulation? Illustrate with an example in C++?
The wrapping up of data and functions into a single unit is encapsulation.

Eg:

class sample
{
 int x;            
 float y;    
 public:
 void enter()
 {
  cin>>x>>y;
 }
 void display()
 {
  cout<<x<<y;
}};
 void main()
 { sample s;
   s.enter();  //s , the object and enter(), the function are both wrapped together as a 
}                    // single unit to execute the member function enter()

9)      What is the difference between a concrete class and an abstract class?
The only real difference is that a concrete class can be instantiated because it provides (or inherits) the implementation for all of its methods. An abstract classcannot be instantiated because at least one method has not been implemented.Abstract classes are meant to be extended.
10)  What is polymorphism? How is it implemented?
The act of representing a message in more than one form is called polymorphism. Poly means many, morph means changing from one form to another.
Polymorphism is represented by way of function overloading.
Eg:
Eg:
void prnsqr(int i);//overloaded for integer
void prnsqr(char c);// overloaded for character
void prnsqr(float f);//overloaded for float
void prnsqr(double d);//overloaded for double


void prnsqr(int i)
{
cout<<"Integer "<<i<<"\n";
}
void prnsqr(char c)
{
cout<<c<<" is a character "<<"\n";
}
void prnsqr(float f)
{
cout<<" Float "<<f"\n";
}
void prnsqr(double d)
{
cout<<"Double "<<d<<"square is"<<i*i<<"\n";
}


No comments:

Post a Comment