C++/ Java Interview Questions - Tech Mahindra
1. What is the output of the following program?
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout«re; cout«im;}
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
a) 4,5 b) 3,5 c) 5,5 d) None of the above
2. What is the error in the class declaration?
class something
{
char *str;
public:
something(){
st = new char[10]; }
~something()
{
delete str;
}
};
a) pointer not defined
b) st not defined
c) deleting a pointer is wrong
d) None of the above
3. Find the error in the class declaration?
class temp
{
int value1;
mutable int value2;
public :
void fun(int val)
const{
((temp*) this)->value1 = 10;
value2 = 10;
}
};
a) mutable is wrongly used
b) const is not a function
c) wrong use of pointer
d) None of the above
4. What is spanning tree?
5. Explain traveling salesman problem?
6. What is the difference between BFS and DFS?
7. Write down the prim’s algorithm?
8. What is JVM? What is its use?
9. How to do memory management in JAVA?
10. Why are constructors and destructors used?
Discussion
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 10.constructions are used to construct the class objets,
destructions used to go out of space of class objects - RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 9.collects the information reclamied by the object. and then it determines the object no longer accessible
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- jvm complies binary codes
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 6. bfs is a single search
dfs is multiple search - RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 5.problem to find out the shortest path passes though the each set only once
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- inter connection between two graphs of two terms
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 3.wrong use of pointer
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 2.deleting a pointer
- RE: C++/ Java Interview Questions - Tech Mahindra -roopesh (06/13/14)
- 1.(5,5)