can we declare an object of a class in another class?(assume
both class as public classes)



can we declare an object of a class in another class?(assume both class as public classes)..

Answer / poonam

yes,we can declare the object of one class into another class. The kind of relationship is called Containership or nesting. this is one of the best feature of c++ which allow inheritence and reusability.
for eg:
class alpha {.....};
class beta {....};
class gamma
{
alpha a;
beta b;
...
};


Creation of one object into another is very different from that of an independent object. Independent object is created
by cnstructors when declared with the arguments.


for further details refer c++ by balguruswamy page no.240

Is This Answer Correct ?    13 Yes 0 No

Post New Answer

More C++ Code Interview Questions

We need to write the function to check the password entered is correct or not based on the following conditions.. a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters and any special characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character

0 Answers  


How to Split Strings with Regex in Managed C++ Applications?

0 Answers   Microsoft,


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

0 Answers  


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

0 Answers  


Write an algorithm that receives a string and reverses it.

2 Answers  






Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are 200. 20 in each row. Each row is referred by the Character, "A" for the first row and 'J' for the last. And each seat in a row is represented by the no. 1-20. So seat in diffrent rows would be represented as A1,A2....;B1,B2.....;........J1,J2... Each cell in the table represent either 0 or 1. 0 rep would seat is available , 1 would represent seat is reserved. Booking should start from the last row (J) to the first row(A). At the max 20 seats can be booked at a time. if seats are available, then print all the seat nos like "B2" i.e (2 row, 3 col) otherwise Print "Seats are not available." and we must book consecutive seats only.

1 Answers   Nagarro,


Write A C++ Program To Input A Number Between 20 To 99 And Display Its Numbername?

3 Answers   TCS,


find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

0 Answers  


develop a program to calculate and print body mass index for 200 employees

0 Answers   Jomo Kenyatta University,


A research student is given a singly-linked list. Each node of the list has a color, which is either “Black” or “White”. He must find if there are more black nodes than white nodes, or vice versa. His advisor gives him 5,000Rs to buy a computer to do the work. He goes to the computer store and finds a slightly defective computer which costs a mere 3,000Rs. This computer has the small problem of not being able to do arithmetic. This means that he cannot use a counter to count the nodes in the list to determine the majority color. The computer is otherwise fully functional. He has the evil idea that he could buy the defective computer and somehow use it to do his work, so that he can use the rest of the money on enjoyment. Show how he can accomplish this amazing task. Write code for an algorithm called ‘findMajorityColor’ which takes a singly-linked list, L, with n nodes and returns the majority color among nodes of L. This algorithm should have the same asymptotic running time as counting the nodes (O(n)). Note: No arithmetic is allowed.

2 Answers  


A Binary no. is given, we hav to find it's decimal equivalent.

2 Answers   Microsoft,


what is the difference between int &r and int& r

3 Answers  


Categories