wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> microsoft >> Object Oriented Concepts
(Message started by: ray on Nov 14th, 2008, 1:07pm)

Title: Object Oriented Concepts
Post by ray on Nov 14th, 2008, 1:07pm
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.

Title: Re: Object Oriented Concepts
Post by towr on Nov 14th, 2008, 1:41pm

on 11/14/08 at 13:07:53, 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?

Title: Re: Object Oriented Concepts
Post by ray on Nov 14th, 2008, 2:53pm
well then let it be


ClassA
{
   ClassB b=NULL;

    public ClassA()
   {
        b= new ClassB();
   }
}

 

Title: Re: Object Oriented Concepts
Post by towr on Nov 15th, 2008, 9:51am
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.

Title: Re: Object Oriented Concepts
Post by ray on Nov 15th, 2008, 3:32pm
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.

Title: Re: Object Oriented Concepts
Post by kvcodes on Aug 29th, 2014, 10:00pm
OOPs concepts are
1)object
2)class
3)encapsulation
4)abstraction
5)polymorphism
6)inheritance
7)message passing
8)dynamic binding

Title: Re: Object Oriented Concepts
Post by anglia on Aug 11th, 2015, 5:51am
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();
}
}



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board