question লেবেলটি সহ পোস্টগুলি দেখানো হচ্ছে৷ সকল পোস্ট দেখান
question লেবেলটি সহ পোস্টগুলি দেখানো হচ্ছে৷ সকল পোস্ট দেখান

সোমবার, ১৬ অক্টোবর, ২০১৭

What is the differentiate between structure and class ?

The differentiate between structure and class 

                            1. Members of a class are private by defaults and members of a structure are public by defaults . Examples

class Sabbir
{
 int s;
};
int main( )
{
    Sabbir t;
  t.s=40;
getchar( );
return 0;
}
If you run this program computer shows error because here  s is private .

 struct Sabbir
{
 int s;
};
int main( )
{
    Sabbir t;
    t.s=40;
   getchar( );
   return 0;
}
If you run this program compiler work properly  because here  s is public .

2. When deriving a struct from a class/struct,default access-specifier for a base class/struct is public.And when deriving a class , default specifier is private .

Example

class Sabbir
{
 int s;
};
class derived : Sabbir { };
int main( )
{
    Derived d;
 
    d.s=40;
   getchar( );
   return 0;
}

Here the coding is not working beacuse compiler shows error inheritance is private .

class Sabbir
{
 int s;
};
struct derived : Sabbir { };
int main( )
{
    Derived d;
 
    d.s=40;
   getchar( );
   return 0;
}

Here the coding is  working beacuse compiler shows that inheritance is public.



Share:

Write some features of Object Oriented Programming (OOP)

The most important of OOP features are
1. Object
2. Class
3. Data hiding
4. Encapsulation
5. Dynamic Binding
6. Inheritance
7. Message passing
8. Polymorphism 

Let us consider a short  overview  some of these important features of OOP

1. Object
         Object is an instance of a class.

2. Class
        The class is the mechanism that is used to create objects. Classes are user defined data type. Once a class has been created, we can make any kind of object belonging to that  class.
A class is declared using the class keyword. The syntax of a class declaration is similar to that of a structure. Its general form is shown here

class class_name
       {
         //Private functions and variables
    public:
         //Public functions and variables
       }object_class;
3.Encapsulation
             Encapsulation is the mechanism that binds together code and the data manipulates and keeps safe from outside interference and misuse .

4. Polymorphism 
             Polymorphism is the quality that allows one name to be used for two or more related but technically different purposes.

5.Inheritance
            Inheritance is the process by which one object can acquire the  properties of another .



Share: