Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object Oriented Class Modeling C#

Tags:

c#

oop

I have two different classes namely Car and Radio. How I can make sure that class Radio can be only used by class Car? Or is there better implementation here?

I'm coding in c#.

class Car
{
    // car has a radio
}  


class Radio
{
    // some properties

        // some methods
        void TurnOn(bool onOff) { }        
}

Thanks in advance.

like image 273
yonan2236 Avatar asked Aug 01 '26 14:08

yonan2236


1 Answers

class Car {

  public Car() {
    myRadio = new Radio();
  }

  private class Radio {
    void TurnOn(bool onOff) {}
  }
}
like image 63
Martin Avatar answered Aug 04 '26 03:08

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!