Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C# Programming › Why does this inherited method work?

Why does this inherited method work?

Posts 1–15 of 19 · Page 1 of 2
Laslod
Laslod
Why does this inherited method work?
Say I have a class:

Code:
 class MachoMan
    {
        public int x;

        public virtual void changex() { x += 10; }
            
    }
And class:

Code:
class MiniMan : MachoMan
    {
        public int y;
        public override void changex()
        {
            base.changex();
            
            y += 10;
            Console.WriteLine(y);
        }
    }
Now I do this:

Code:
 MachoMan ComboMan = new MiniMan();
Alright. If I do
Code:
ComboMan.y
it doesn't work. I can understand that, it's presumably because when I made ComboMan type MachoMan, it only had the fields and methods of MiniMan. And since I made it a new MiniMan , it has the fields and methods of MachoMan, but what MiniMan has filled in those field & methods. So basically, I thought it's not suppost to have Y becuase MachoMan doesn't have that. So calling ComboMan.changex() shouldn't work because in the MiniMan class I made a new variable that MachoMan doesn't have, and manipulated it in the changex() method.

But, when I do this
Code:
ComboMan.changex();
It works fine????? Wtf? Why? If that works then that means that ComboMan still has all of the fields of MachoMan. But how can that be when I made it type MachoMan??

----------------------------------------------------------------------------------------------------------------------
I made the names different. If i'm being confusing , my question is this. So miniman inherits from machoman, and miniman has a y field which machoman does not have.
When I make comboman of type machoman but set it equal to miniman, it will have this:

Code:
public override void changex()
{
base.changex();

y += 10;
Console.WriteLine(y);
}
code inside the changex method instead of this

Code:
public virtual void changex() { x += 10; }
PLUS I am not able to do ComboMan.Y becaue it doesn't recognise it! THAT leads me to believe that ComboMan does not have all the fields and methods of MiniMan even if it is set to MiniMan. Instead it has all the fields and methods of MachoMan but they're filled in with what's in MiniMan. So instead of having the changex do the original Machoman's changex, it does what the MiniMan has filled in for it ( which is increment y with 10).

So my question is, if ComboMan doesn't have the fields and methods of MiniMan, but instead has the fields and methods of MachoMan with what MiniMan has filled in for them, then why does the changex method work? It increments y with 10, but y is a field exclusive to MiniMan. So since ComboMan doesn't have the fields and methods of MiniMan, therefore doesn't have y, it shouldn't work. So why does it work? I hope I've made myself comprehensible.
#1 · edited 13y ago · 13y ago
abuckau907
abuckau907
"...If that works then that means that inherites still has all of the fields of inherits. But how can that be when I made it type Inherit??"

Because you didn't make it of type 'inherit', you made the variable of type 'inherits'
Code:
Inherit inherites = new Inherits(); <--I see both classes..
Unless I mis-read. ?

But I'm really not the one to explain why, sry.
#2 · edited 13y ago · 13y ago
Laslod
Laslod
Huh? I thought when I did

Inherit inherites = new Inherits();

I made an inherites of type Inherit and set it equal to Inherits
#3 · 13y ago
abuckau907
abuckau907
You declare it one type, but can set it = another related type.

So, which data type is the variable 'inherites'...?

Declared as inherit, but set = to inhertis. //Is it an 'inherit' or 'inherits' object ?
#4 · edited 13y ago · 13y ago
Laslod
Laslod
Quote Originally Posted by abuckau907 View Post
You declare it one type, but can set it = another related type.

So, which data type is the variable 'inherites'...?

Declared as inherit, but set = to inhertis. //Is it an 'inherit' or 'inherits' object ?
It's an inherit object declared as inherits.
#5 · 13y ago
abuckau907
abuckau907
I know, I said that :P So what's the question ?

"If that works then that means that inherites still has all of the fields of inherits."
Well, you did set it =new inherits object. I'm not sure what you're *trying* to do.
#6 · edited 13y ago · 13y ago
Auxilium
Auxilium
You can start by having names a little different.
#7 · 13y ago
abuckau907
abuckau907
Agreed. Naming is supert important.
@Laslod - maybe re-make the 2 classes: try something semi-obvious and familiar. I suggest a 'dog' class, and maybe a 'super cop dog' class that inherits from it.
#8 · 13y ago
Laslod
Laslod
@Virtual Void @abuckau907

I made the names different. If i'm being confusing , my question is this. So miniman inherits from machoman, and miniman has a y field which machoman does not have.
When I make comboman of type machoman but set it equal to miniman, it will have this:

public override void changex()
{
base.changex();

y += 10;
Console.WriteLine(y);
}
code inside the changex method instead of this

public virtual void changex() { x += 10; }

PLUS I am not able to do ComboMan.Y becaue it doesn't recognise it! THAT leads me to believe that ComboMan does not have all the fields and methods of MiniMan even if it is set to MiniMan. Instead it has all the fields and methods of MachoMan but they're filled in with what's in MiniMan. So instead of having the changex do the original Machoman's changex, it does what the MiniMan has filled in for it ( which is increment y with 10).

So my question is, if ComboMan doesn't have the fields and methods of MiniMan, but instead has the fields and methods of MachoMan with what MiniMan has filled in for them, then why does the changex method work? It increments y with 10, but y is a field exclusive to MiniMan. So since ComboMan doesn't have the fields and methods of MiniMan, therefore doesn't have y, it shouldn't work. So why does it work? I hope I've made myself comprehensible.
#9 · 13y ago
abuckau907
abuckau907
post all the new code.. Need to see how you declare the variables etc. I can assume, but having 100% of your code in front of me makes both our lives easier.

Your class "relationships" still aren't very good. It's not "clear" that a 'miniman' is a 'machoman', or vice versa? You should have a base class of "man" and then 2 derived classes of "miniman" and "machoman" maybe. ? Really really doesn't matter, but naming is everything, and having something named "changex" doesn't exactly make the problem more clear.

(obviously not real code, but something similar to)

class dog

void func Bark()
{
<< "A basic dog bark"
}


clas SuperCopDog : dog
{
overrides func Bark()
<<" SUPER LOUD cop dog bark"
}


--create some objects and see which method actually gets called.

The whole point of polymorphism is to allow you to use 1 class in place of another, but ofc some of the functions won't be accessible(depending on the TYPE of your variable). I can't explain very well, sorry.

If you can/can't access an object indsie your class....the problem is how you defined your classes and their relationships, so I'm not sure what you're asking when you say (for example) "well I don't see anything after typing in myObj. (see the dot)" because...that's how it's supposed to work. It it does/doesn't allow you to access some variable, it's not an error, that's just how c# does inheritance / how you defined your classes. ? Even though I'm not sure what to say, let's try one more time. Paste all ur code and we'll go from there.

[b]edit:[b/] you edited your original post. I guess that works, but not what I meant.? Please paste below this msg.
#10 · edited 13y ago · 13y ago
Laslod
Laslod
Quote Originally Posted by abuckau907 View Post
post all the new code.. Need to see how you declare the variables etc. I can assume, but having 100% of your code in front of me makes both our lives easier.

Your class "relationships" still aren't very good. It's not "clear" that a 'miniman' is a 'machoman', or vice versa? You should have a base class of "man" and then 2 derived classes of "miniman" and "machoman" maybe. ? Really really doesn't matter, but naming is everything, and having something named "changex" doesn't exactly make the problem more clear.

(obviously not real code, but something similar to)

class dog

void func Bark()
{
<< "A basic dog bark"
}


clas SuperCopDog : dog
{
overrides func Bark()
<<" SUPER LOUD cop dog bark"
}


--create some objects and see which method actually gets called.

The whole point of polymorphism is to allow you to use 1 class in place of another, but ofc some of the functions won't be accessible(depending on the TYPE of your variable). I can't explain very well, sorry.

If you can/can't access an object indsie your class....the problem is how you defined your classes and their relationships, so I'm not sure what you're asking when you say (for example) "well I don't see anything after typing in myObj. (see the dot)" because...that's how it's supposed to work. It it does/doesn't allow you to access some variable, it's not an error, that's just how c# does inheritance / how you defined your classes. ? Even though I'm not sure what to say, let's try one more time. Paste all ur code and we'll go from there.

[b]edit:[b/] you edited your original post. I guess that works, but not what I meant.? Please paste below this msg.
Huh? I don't get what you're saying. There's no new code I just edited the main one and made my message clearer because you guys told me to change the names.
I just want to know the why. I know how it works but I want to know why it works. I'll put my clarification attempt on the original post so it's better visible I gguess.
#11 · 13y ago
abuckau907
abuckau907
why: Because that's how C# implements inheritance. I'm not sure what you mean.

Your object was declared as the "base" class, but set = "derived" class.


You want to know why it can/can't access certain members of both classes?
Idk 'why', sry.
#12 · edited 13y ago · 13y ago
Laslod
Laslod
Quote Originally Posted by abuckau907 View Post
why: Because that's how C# implements inheritance. I'm not sure what you mean.

Your object was declared as the "base" class, but set = "derived" class.


You want to know why it can/can't access certain members of both classes?
Idk 'why', sry.
Yes I want to know why ComboMan seemingly doesn't have the Y field but is able to change it with the changex() method without generating an error.
#13 · 13y ago
abuckau907
abuckau907
public virtual void changex


Virtual Functions cause this behavior - by design.


I really can't explain anymore, sry. If you have skype, feel free too add me. I'm obviously failing at explaining, I'm sorry.


-Pick 2 different classes, please. It will be "more obvious" if you choose the proper classes.

Classes should exhibit the "is a" relationship. "miniman" is a "machoman" seems a little weird, but doesn't *really* matter.
#14 · edited 13y ago · 13y ago
Jason
Jason
You need to read up on how inheritance works. Although you constructed a MiniMan instance, you stored it in a variable of type MachoMan. This is perfectly valid, however because you're now using a MachoMan variable, you no longer have access to additional methods/variables that the MiniMan class made available. You do, however, have access to the methods made available in the MachoMan base class (changex). This is where inheritance can get tricky to wrap your head around, so I recommend doing some proper reading on the subject. When you call changex(), you're actually going to call the MiniMan implementation of changex(), not the original MachoMan implementation, because your variable is an instance of the MachoMan derived class, MiniMan.

Take a look at this article for a more in-depth explanation of how inheritance and polymorphism work. It can take some time to wrap your head around it, but it's well worth learning.
#15 · 13y ago
Posts 1–15 of 19 · Page 1 of 2

Post a Reply

Similar Threads

  • Why does this not work?By extremehack in Combat Arms Hack Coding / Programming / Source Code
    8Last post 16y ago
  • Why does this dont work?By skulhead in WarRock Hack Source Code
    11Last post 15y ago
  • Why does this dont work?By skulhead in WarRock Hack Source Code
    10Last post 15y ago
  • Why does 2.0 bypass work for me but not 3.5?By Mattsta in Combat Arms Hacks & Cheats
    12Last post 18y ago
  • Why does this site run so god damn slow?By shazbork in Flaming & Rage
    24Last post 18y ago

Tags for this Thread

None