C
C#2y ago
randomokay

❔ homework

drawing memory
29 Replies
randomokay
randomokayOP2y ago
they want me to draw the memory after running the Three t command
randomokay
randomokayOP2y ago
i cant figure it out even with the answer i start with class three : one right?
Pobiega
Pobiega2y ago
oh, you're supposed to graphically represent the objects and their references?
randomokay
randomokayOP2y ago
ye how do i start
Pobiega
Pobiega2y ago
Three makes sense, since that is your entrypoint, and also the only class with only 1 instance I'd start with drawing three and the two fields inside it.
randomokay
randomokayOP2y ago
Ok p = new Two(new One(), 1); the first command what do they mean with new One
Anu6is
Anu6is2y ago
the new keyword creates an instance of a class.... in this case One
randomokay
randomokayOP2y ago
it refers to class one right
Anu6is
Anu6is2y ago
because the constructor for Two expects a One and an int yes, it creates an instance of class one
randomokay
randomokayOP2y ago
but what does the , 1 mean
Anu6is
Anu6is2y ago
^
public Two(One b, int c)
{
//code here
}
public Two(One b, int c)
{
//code here
}
randomokay
randomokayOP2y ago
ooh
Anu6is
Anu6is2y ago
that's the constructor for two
randomokay
randomokayOP2y ago
but class three : one cant access class two?
Anu6is
Anu6is2y ago
what do you mean by can't access it exactly?
randomokay
randomokayOP2y ago
its in a different class
Anu6is
Anu6is2y ago
Two and Three are classes you can't really say Two is "in" a different class... it is a class of its own
randomokay
randomokayOP2y ago
ye but dont i need a reference to access information about class two
Anu6is
Anu6is2y ago
so you are creating an instance of class two
randomokay
randomokayOP2y ago
like with inheritance i can access information about class 1
Anu6is
Anu6is2y ago
you aren't yet acessing information about it this isn't accessing anything, it's creating
randomokay
randomokayOP2y ago
oh oke
Anu6is
Anu6is2y ago
again, the new key word creates an instance of a class so new Two(...) is creating a instance of Two
randomokay
randomokayOP2y ago
what does it take as argument p = new Two(new One(), 1); for this one it takes int c = 1 and b = new One?
Anu6is
Anu6is2y ago
yes
randomokay
randomokayOP2y ago
ah i think i get it now thanks for the help
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?