wu :: forums
« wu :: forums - Object Oriented Concepts »

Welcome, Guest. Please Login or Register.
Mar 29th, 2024, 12:31am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   microsoft
(Moderators: Icarus, SMQ, towr, william wu, Eigenray, Grimbal, ThudnBlunder)
   Object Oriented Concepts
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Object Oriented Concepts  (Read 4261 times)
ray
Newbie
*





   


Posts: 6
Object Oriented Concepts  
« on: Nov 14th, 2008, 1:07pm »
Quote Quote Modify 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: male
Posts: 13730
Re: Object Oriented Concepts  
« Reply #1 on: Nov 14th, 2008, 1:41pm »
Quote Quote Modify 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 Quote Modify 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: male
Posts: 13730
Re: Object Oriented Concepts  
« Reply #3 on: Nov 15th, 2008, 9:51am »
Quote Quote Modify 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 Quote Modify 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
*





  http://www.kvcodes.com  


Gender: male
Posts: 3
Re: Object Oriented Concepts  
« Reply #5 on: Aug 29th, 2014, 10:00pm »
Quote Quote Modify Modify

OOPs concepts are
1)object
2)class
3)encapsulation
4)abstraction
5)polymorphism
6)inheritance
7)message passing
Cooldynamic binding
IP Logged
anglia
Junior Member
**





   
WWW

Gender: female
Posts: 60
Re: Object Oriented Concepts  
« Reply #6 on: Aug 11th, 2015, 5:51am »
Quote Quote Modify 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
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

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