ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Programming-Languages >> C++
 
  STL (45)  OOPS (186)  C++-General (222)
 


 

Back to Questions Page
 
Question
can you explain how to use JavaBean in Project
Rank Answer Posted By  
 Question Submitted By :: Yuga.reddi08
This Interview Question Asked @   Infosys , Satyam
I also faced this Question!!   © ALL Interview .com
Answer
java bean is a simple java class 
 use the project modelview useing (get,set methodimplemet)
 
0
Koti
 
 
Question
Tell me the scenario,Where we can use interfaces or 
Abstract class.And What is the difference between 
interfaces and abstract class?
Rank Answer Posted By  
 Question Submitted By :: Mueen Khan
I also faced this Question!!   © ALL Interview .com
Answer
abstract class contains function prototypes and function
definations also
 but interface ccontains onlu function prototypes which are
used in deriving object declarations
 
2
Seshu
 
 
Answer
there is not interface and abstrcat keyword in C++.
but in CLR and Java
 
0
Aaa
 
 
 
Answer
In relation to C# (not C++):
1. Interfaces are like abstract class where all member 
functions as abstract but cannot have any data members, 
constructors or destructors. Classes using interfaces are 
forced to implement all the methods in the interface.
2. Does not implement any methods. ie only used as a 
template for derived classes to use.
3. All members of interface are public. ie in Interface you 
only have to state long Function(); but in a class you have 
to state public abstract long Function();
4. A class can have multiple inheritence with an interface 
but not a class.
5. Also structures in C# cannot inherit from other classes 
of structures but can implement an interface allowing you 
to implement more features to your class.
By using interfaces you are not making any assumptions 
about the functionality. You want to make sure your classes 
using the interfaces implement the functionality of all the 
methods in your Interface.
With all above in mind you can probably find more uses for 
an interface.
One example: You have many forms of communication like 
FileIO or database or IPC. All these forms of communication 
will need to features like Open and Close either a file or 
a connection Read or write etc. You would then define an 
interface with these features for your concrete classes. 
You can then use the Interface as a base class pointer like 
in C++ to access the derived class's functions.
 
0
Kaushik Thakrar
 
 
Question
difference between c and c++?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Infosys , Info
I also faced this Question!!   © ALL Interview .com
Answer
=>c does not a class/object concept
   =>c++ provides data encapsulation,data  
abstraction,polymorphism.
   =>c++ support all c syntax
   =>in c passing value to a function is "call by value" 
     where c++ its "call by reference"
 
0
Mahesh
 
 
Answer
c is procedure oriented language and gives importance to 
procedure that is functions rather than data.c is middle 
level language.
c++ is object oriented language and gives importance to 
object that is data 
c++ is high level language
 
3
Asri
 
 
Answer
C is procedure oriented programming & c++ is object 
oriented programming.
c++ contains classes & object,c++ does not require format 
specifier for printing & scanning variables.
 
0
Kaustubh Mahajan
 
 
Answer
C++ is the hight level language, but C is low level 
language.

C++ can support of all function of C, but C can't support 
of all function of C++.

We can work with Class in C++, But we can't work with Class 
in C

C++ is a object oriented language but C is not OOPS

C is the Top to bottom , but C++ is bottom to Top language.
 
0
Manish Jangid
 
 
Answer
1] c is procedure oriented programing & c++ is object 
oriented programing.
2] we can't do programing through class in c,but we can do 
in c++.
3] c is top to bottom programing approach, c++ is bottom to 
top programing approach.
4] c++ is high level language,c is low level language.
5] c++ accept all the feature & function of of c & its own 
properties,but it is not happened in c.
6] data can move in c openly arround in the system from 
function to function.In c++ data is hidden can't be 
accessed by external function.
 
0
Abhisek Pramanik
 
 
Answer
1 C++ OBJECT ORIENTED PROGRAMMING BUT 'C' IS PROCEDURE
ORIENTED PROGRAMMING
2 C++ IS HIGH LEVEL LANGUAGE BUT 'C' IS LOW LEVEL LANGUAGE
3 C++ IS GOING TO BOTTOM TO TOP BUT 'C' IS GOING TO TOP TO 
BOTTOM
 
0
Shanky Garg
 
 
Answer
Main difference between c and c++ are:
1.) In c++, there is strict typechecking and in c, there is 
no strict typechecking. So, many programes which can 
compiled by c compiler cannot be compiled by c++ compiler.

2.) In c, there is only "EARLY BINDING", whereas in c++, 
there are "EARLY BINDING & LATE BINDING".

3.)C++ IS HIGH LEVEL LANGUAGE BUT 'C' IS LOW LEVEL LANGUAGE.

4.)In c++,there is a new concept of "INLINE FUNCTIONS", 
whereas in c, there are macros.

5.)C++ is a object oriented language but C is not OOPS.
 
0
Munish Kumar
 
 
Answer
c is structured design,c++ is object oriented design 
c is top-down approach,c++ is bottom-top approach
c++ is required acces specifiers,c is not required acces 
specifiers
c++ is client server model
 
0
Muneeswari
 
 
Question
why can't we declare data member of class auto register or 
extern
Rank Answer Posted By  
 Question Submitted By :: Rajnesh
I also faced this Question!!   © ALL Interview .com
Answer
since data members gets memory allocated through object not 
individual..so always memory allocated for object...
otherwise u might get error like illegal storage class
 
0
Kavitha Shetty
 
 
Question
what is the usage of clas templates
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
templates are used to create generic functions as well as 
classes..which can support miltiple data types..
they are mainly used when algorithm is commom for diff data 
types...so we dont hav to implement again and again for 
diff data types ..we make a generic func. which works for 
all...
 
4
Saurabh Chauhan
 
 
Answer
We can able to operate "class template" functionalities in 
generic way, which supports different data types.
 
0
James Prasanna.j
 
 
Answer
through this we can make generic function. so this function 
will work for any data type.
 
0
Anil Kumawat
 
 
Answer
Template is a mechanism that allows one function or class to 
deal with diffrent data types.
Using templates we can design a template class that operates on 
diffrent data types.
 
0
Keshav.gadde
 
 
Answer
A template is a C++ feature that allows functions and
classes to be defined with any type.Class template is a
template used to generate template classes. You cannot
declare an object of a class template.Template class is an
instance of a class template.
 
0
Anil Bisht
 
 
Question
how to swap to variables without using thrid variable in java?
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
int x = 15;
int y = 20;
System.out.println(x+" "+y);
x ^= y;
y ^= x;
x ^= y;
System.out.println(x+" "+y);
 
0
Mani
 
 
Answer
It’s pretty simple:

	int a = 12;
	int b = 34;

	a = a + b;
	b = a - b;
	a = a - b;

And for real cowboys, it could be simplified further:

	a -= (b = (a += b) - b);
 
0
Igor Polivanyi
 
 
Answer
a=a^b^(b=a);

Hemant Verma
FameofLight@gmail.com
 
0
Hemant Verma
 
 
Question
Please tell me the oops concept with detailed answer
Rank Answer Posted By  
 Question Submitted By :: Rsenthilkumar1986
This Interview Question Asked @   EEE
I also faced this Question!!   © ALL Interview .com
Answer
the basic concepts of OOP's are
1.class- it is a collection of variables and methods
2.odjects- it is the run time entity(it is same as real 
world objects)
3.data abstraction and encapsulation-essential features of 
data not including the background details
4.polymorphism-same name with more than one form
5.inheritance-concept of acquiring the base class properties
there are 5 types of inheritance
1.single inheritance
2.multiple inheritance
3.multilevel inheritance
4.hierarchical inheritance
5.hybrid inheritance
6.dynamic binding- data bind at runtime
7.message passing-communicating information with one another
 
0
Saranya
 
 
Answer
oops means that object oriented programming, the precedure 
ifollowed inc lan...
 
0
Sathya
 
 
Answer
Oops is an acronym for object oriented programming language 
or object oriented paradigm

Building blocks of oops are

1) Data Encapsulation :
Hiding non essential things from an user

2) Abstraction
Implementation of data encapsulation

3) Inhertitance
Reusability of code

4) Polymorphism
The ability of a function that can act on different data 
types in different ways
 
5
M.shanmuga Sundaram
 
 
Answer
There are mainly 4 object oriented principals.

1)ABSTAACTION:process of providing necessary properties & 
operations of an object.

2)ENCAPSULATION:process of providing all the properties
&operations of entity in one place.
properties...>variables
operations...>methods
place     ...>class

3)INHERITANCE:process of writing a new class(derived 
class,sub class,chiled class) by using the functionality of 
existing class(super class,base class,parent class)

4)POLYMORPHISM:one form behaving differently in different 
situations.
ex:tv remote button,same button used to make the tv on & 
off.
 
0
Mahesh_b.tech@2008
 
 
Question
How Do you Code Composition and Aggregation in C++ ?
Rank Answer Posted By  
 Question Submitted By :: Gurunathchoukekar
This Interview Question Asked @   IBM , Net
I also faced this Question!!   © ALL Interview .com
Answer
An aggregation is a specific type of composition where no 
ownership between the complex object and the subobjects is 
implied. When an aggregate is destroyed, the subobjects are 
not destroyed.

     For example, consider the math department of a school, 
which is made up of one or more teachers. Because the 
department does not own the teachers (they merely work 
there), the department should be an aggregate. When the 
department is destroyed, the teachers should still exist 
independently (they can go get jobs in other departments).

Because aggregations are just a special type of 
compositions, they are implemented almost identically, and 
the difference between them is mostly semantic. In a 
composition, we typically add our subclasses to the 
composition using either normal variables or pointers where 
the allocation and deallocation process is handled by the 
composition class.

Let’s take a look at our Teacher and Department example in 
more detail.

view plaincopy to clipboardprint?
  
#include <string>   
using namespace std;   
  
class Teacher   
{   
private:   
    string m_strName;   
public:   
    Teacher(string strName)   
        : m_strName(strName)   
    {   
    }   
  
    string GetName() { return m_strName; }   
};   
  
class Department   
{   
private:   
    Teacher *m_pcTeacher; // This dept holds only one 
teacher   
  
public:   
    Department(Teacher *pcTeacher=NULL)   
        : m_pcTeacher(pcTeacher)   
    {   
    }   
};   
  
int main()   
{   
    // Create a teacher outside the scope of the 
Department   
    Teacher *pTeacher = new Teacher("Bob"); // create a 
teacher   
    {   
        // Create a department and use the constructor 
parameter to pass   
        // the teacher to it.   
        Department cDept(pTeacher);   
  
    } // cDept goes out of scope here and is destroyed   
  
    // pTeacher still exists here because cDept did not 
destroy it   
    delete pTeacher;   
}  

#include <string>
using namespace std;

class Teacher
{
private:
    string m_strName;
public:
    Teacher(string strName)
        : m_strName(strName)
    {
    }

    string GetName() { return m_strName; }
};

class Department
{
private:
    Teacher *m_pcTeacher; // This dept holds only one 
teacher

public:
    Department(Teacher *pcTeacher=NULL)
        : m_pcTeacher(pcTeacher)
    {
    }
};

int main()
{
    // Create a teacher outside the scope of the Department
    Teacher *pTeacher = new Teacher("Bob"); // create a 
teacher
    {
        // Create a department and use the constructor 
parameter to pass
        // the teacher to it.
        Department cDept(pTeacher);

    } // cDept goes out of scope here and is destroyed

    // pTeacher still exists here because cDept did not 
destroy it
    delete pTeacher;
}
In this case, pTeacher is created independetly of cDept, 
and then passed into cDept’s constructor. Note that the 
department class uses an initialization list to set the 
value of m_pcTeacher to the pTeacher value we passed in. 
When cDept is destroyed, the m_pcTeacher pointer destroyed, 
but pTeacher is not deallocated, so it still exists until 
it is independently destroyed.

To summarize the differences between composition and 
aggregation:

Compositions:

Typically use normal member variables 
Can use pointer values if the composition class 
automatically handles allocation/deallocation 
Responsible for creation/destruction of subclasses 
Aggregations:

Typically use pointer variables that point to an object 
that lives outside the scope of the aggregate class 
Can use reference values that point to an object that lives 
outside the scope of the aggregate class 
Not responsible for creating/destroying subclasses 
It is worth noting that the concepts of composition and 
aggregation are not mutually exclusive, and can be mixed 
freely within the same class. It is entirely possible to 
write a class that is responsible for the 
creation/destruction of some subclasses but not others. For 
example, our Department class could have a name and a 
teacher. The name would probably be added to the department 
by composition, and would be created and destroyed with the 
department. On the other hand, the teacher would be added 
to the department by aggregate, and created/destroyed 
independently.

It is also possible to create other hybrid 
aggregate/composition schemes, such as where a class holds 
independent subobjects like an aggregate, but will destroy 
them when the class goes out of scope like a composition.

While aggregates can be extremely useful (which we will see 
more of in the next lesson on container classes), they are 
also potentially dangerous. As noted several times, 
aggregates are not responsible for deallocating their 
subobjects when they are destroyed. Consequently, if there 
are no other pointers or references to those subobjects 
when the aggregate is destroyed, those subobjects will 
cause a memory leak. It is up to the programmer to ensure 
that this does not happen. This is generally handled by 
ensuring other pointers or references to those subobjects 
exist when the aggregate is destroyed
 
5
Lekshmi
 
 
Question
how to find no of instances of an object in .NET?
Rank Answer Posted By  
 Question Submitted By :: Santosh
This Interview Question Asked @   Infosys
I also faced this Question!!   © ALL Interview .com
Answer
When u create object of class it invoke Constructor. So 
declare variable and increase in Constructor and 
parametrised Constructor you will get number.
 
0
Gouri Patil
 
 
Question
swapping program does not use third variable
Rank Answer Posted By  
 Question Submitted By :: Vinothkumaar
I also faced this Question!!   © ALL Interview .com
Answer
class swap
{
public:
int a,b;
void swapp()
{
a = a + b;
b = a - b;
a = a - b;
}
};
class swap s1.
s1.swapp();
cout<<a<<b;
 
0
Jayasrinivas.donavalli
 
 
Answer
void main()
{
int a,b;//example a=10,b=12;
a=a+b;//a=22
b=a-b;//b=10;
a=a-b;//a=12
}
 
0
Jayabalan.s
 
 
Answer
void main()
{
int a,b;//example a=10,b=12;
a=a~b;//a=22
b=a~b;//b=10; 
a=a~b;//a=12
}


NOTE:
    ~=XOR operator( not able to write xor
            operator so iam using this symbol which is not 
             correct)
 
0
Abdul Rahman
 
 
Answer
swap(a,b);
{
  a=a+b;
  b=a-b;
  a=a-b;
}
Explenation:
if a=5 and b=10
   a=a+b(5+10)=15
   b=a-b(15-10)=5------------swaped here
   a=a-b(15-5)=10------------
 
0
Venkanna
 
 
Question
is throwing exception from a constructor not a good practice ?
Rank Answer Posted By  
 Question Submitted By :: Abhishek
This Interview Question Asked @   Ericsson
I also faced this Question!!   © ALL Interview .com
Answer
Actualy though when an  object is created memory will b
allocated but the process of allocation of memory will be
complete only if conytructor is successfully invoked  so if
constructor  throws an exception memory will not be
allocated for that object.
 
0
Shwetha.v.g
 
 
Answer
yes, because constructor does not throws an exception
 
3
Saranya
 
 
Answer
throwing exception from a constructor is not bad at all. It 
is actually advised to use exceptions when you fail to 
create your object properly due to any reason. In this case 
memory will not be allocated for the object and no 
destructor will be called.
 
0
Vikas Sood
 
 
Answer
Throwing a exception from constructor is perfectly good 
habit. That is how to handle errors in the constructor. 
Smart pointers can also be used in this scenario.
 
0
Manjunath
 
 
Question
why the size of an empty class is 1
Rank Answer Posted By  
 Question Submitted By :: Ekta Gupta
I also faced this Question!!   © ALL Interview .com
Answer
its because an empty class  makes an entry to symbol table (code segment) 
which requires a symoblic mapping of 1 byte
 
0
Abhishek
 
 
Answer
it is becuse each oject must have a different address.
 
0
Kamna
 
 
Answer
Because the fundamental size is a char [viz 1 byte by
default on any 32 bit or 64 bit machine].
 
0
Surender A
 
 
Question
what is static function
Rank Answer Posted By  
 Question Submitted By :: Ekta Gupta
This Interview Question Asked @   Patni
I also faced this Question!!   © ALL Interview .com
Answer
Static functions are functions which can access only static 
variables and local variables.It can be called by class 
name bcoz it is specific for a class in which it is 
defined,not for any specific object of that class.It can 
not be inherited also.
 
0
Aavesh Yadav
 
 
Answer
Static member functions have a class scope and they do not
have access to the 'this' pointer of the class. When a
member is declared as static, a static member of class, it
has only one data for the entire class even though there are
many objects created for the class. The main usage of static
function is when the programmer wants to have a function
which is accessible even when the class is not instantiated.
 
0
Anil Bisht
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com