C
C#14mo ago
randomokay

❔ homework

drawing memory
29 Replies
randomokay
randomokayOP14mo ago
they want me to draw the memory after running the Three t command
randomokay
randomokayOP14mo ago
i cant figure it out even with the answer i start with class three : one right?
Pobiega
Pobiega14mo ago
oh, you're supposed to graphically represent the objects and their references?
randomokay
randomokayOP14mo ago
ye how do i start
Pobiega
Pobiega14mo 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
randomokayOP14mo ago
Ok p = new Two(new One(), 1); the first command what do they mean with new One
Anu6is
Anu6is14mo ago
the new keyword creates an instance of a class.... in this case One
randomokay
randomokayOP14mo ago
it refers to class one right
Anu6is
Anu6is14mo ago
because the constructor for Two expects a One and an int yes, it creates an instance of class one
randomokay
randomokayOP14mo ago
but what does the , 1 mean
Anu6is
Anu6is14mo ago
^
public Two(One b, int c)
{
//code here
}
public Two(One b, int c)
{
//code here
}
randomokay
randomokayOP14mo ago
ooh
Anu6is
Anu6is14mo ago
that's the constructor for two
randomokay
randomokayOP14mo ago
but class three : one cant access class two?
Anu6is
Anu6is14mo ago
what do you mean by can't access it exactly?
randomokay
randomokayOP14mo ago
its in a different class
Anu6is
Anu6is14mo 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
randomokayOP14mo ago
ye but dont i need a reference to access information about class two
Anu6is
Anu6is14mo ago
so you are creating an instance of class two
randomokay
randomokayOP14mo ago
like with inheritance i can access information about class 1
Anu6is
Anu6is14mo ago
you aren't yet acessing information about it this isn't accessing anything, it's creating
randomokay
randomokayOP14mo ago
oh oke
Anu6is
Anu6is14mo ago
again, the new key word creates an instance of a class so new Two(...) is creating a instance of Two
randomokay
randomokayOP14mo 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
Anu6is14mo ago
yes
randomokay
randomokayOP14mo ago
ah i think i get it now thanks for the help
Accord
Accord14mo 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.
Want results from more Discord servers?
Add your server