Author |
Topic: Object Oriented Concepts (Read 4290 times) |
|
ray
Newbie
Posts: 6
|
|
Object Oriented Concepts
« on: Nov 14th, 2008, 1:07pm » |
Quote Modify
|
Suppose you have two classes !) CassA and ClassB one way to instantiate ClassB in ClassA is ClassA { ClassB b = ClassB(); } List all other possible ways.
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Object Oriented Concepts
« Reply #1 on: Nov 14th, 2008, 1:41pm » |
Quote Modify
|
on Nov 14th, 2008, 1:07pm, ray wrote:one way to instantiate ClassB in ClassA is ClassA { ClassB b = ClassB(); } |
| Are you quite sure? Instantiating a class in a declaration of a class sounds iffy. Actually, the real question is, what programming language are you talking about?
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
ray
Newbie
Posts: 6
|
|
Re: Object Oriented Concepts
« Reply #2 on: Nov 14th, 2008, 2:53pm » |
Quote Modify
|
well then let it be ClassA { ClassB b=NULL; public ClassA() { b= new ClassB(); } }
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Object Oriented Concepts
« Reply #3 on: Nov 15th, 2008, 9:51am » |
Quote Modify
|
Without knowing what programming language you're using I can't tell whether what you do is valid; or provide alternative ways of doing it. Personally, I would think NULL is an incompatible type with class B; as well as having the same problem as before with instantiating inside a declaration. And further on, you again assign a pointer (which I assume "new" return) to a class that is not a pointer. But results may vary depending on what programming language you use. Maybe all object are pointers; who knows.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
ray
Newbie
Posts: 6
|
|
Re: Object Oriented Concepts
« Reply #4 on: Nov 15th, 2008, 3:32pm » |
Quote Modify
|
towr you are really brilliant!! The biggest mistake I made was finding different ways immediately without thinking target language, use. The way I answered was : Since it is a has-a relationship (composition), it can be converted to is-a relationship by inheriting classb. Though it may not logically satisfy is-a relationship, but still the derived object will have behavior of classb. Other way was to use reflection concept in java, c# eg: classb b = Class.forName("ClassB"); serialization and de-serialization, and using inner classes.
|
|
IP Logged |
|
|
|
kvcodes
Newbie
Gender:
Posts: 3
|
|
Re: Object Oriented Concepts
« Reply #5 on: Aug 29th, 2014, 10:00pm » |
Quote Modify
|
OOPs concepts are 1)object 2)class 3)encapsulation 4)abstraction 5)polymorphism 6)inheritance 7)message passing dynamic binding
|
|
IP Logged |
|
|
|
anglia
Junior Member
Gender:
Posts: 60
|
|
Re: Object Oriented Concepts
« Reply #6 on: Aug 11th, 2015, 5:51am » |
Quote Modify
|
If you wanted to have Class A instantiate ClassB, then you can simply make Class A and call Class B's constructor. For example: public class ClassA{ public ClassA() { ClassB instance1 = new ClassB(); } }
|
|
IP Logged |
ebooks
|
|
|
|