They are focusing on teaching how arrays and objects work
They give a line or two of code and then explain them, but I don't understand their explanations completely so I am going through the code and making sure I understand everything that is going on... I am hope you can look over the notes I am making (I have no background in programming so everything is new to me and I don't want to be learning things I think are right but are really wrong.)
Also the very last part of the code I don't understand at all, if you can explain it to me it would be appreciated.
I will continue trying to figure it out and if I do I will edit the post with what I think is happening
p.s. sorry if my notes are very sloppy written, I try to write them as I am thinking of whats going on because... I have no idea whats going on.
that is declaing that the dog will have arrays and pets being the variable
Not exactly. You are declaring an Array of the type dog, and call it pets.
Thats like saying, all my pets are gonna be dogs and they are gonna be arranged as an array.
Later you can refer to your pets as pets, pets, etc, and every pet is a dog.
The 7 is new objects with is the dogs and pets being the variable of them.
No. Your initializing your pets Array now, after you declared it in the first line.
Your pets Array is created with enough space to hold 7 dogs, but there are no actual dog-objects in it yet.
You basically saying: give me a place for my pets, and that place needs to have room for 7 dogs.
creating a new objects for every variable which is a new dog object for each pet
Yes, you are actually creating new dogs now, and assigning them to your "group" of pets.
fido being the variable given the object of new dog
This is a declaration and initzialization in one line.
If you pick it apart it says:
first: fido is gonna be a dog.
second: assign a new dog-object to fido.
name is a class variable of the class dog. It means that every dog has a name.
The name may be blank when the dog is "born", but with that line you give him one
telling fido to bark using method applied in another line of code
Applying the dog array to myDogs variable? Don't understand the part after equals
Your doing the same thing you did with pets here, but in a single line
Your declaring a new array called myDogs, thats supposed to hold dogs and then after the equals-sign, you initialize
that array, preparing room to hold 3 dogs. The capital 'D' of "Dog" there is an error if im not mistaking.
More likely an instance variable.
Jon Avadis wrote: . . .
name is a class variable of the class dog. . . .
Initialising variables like that is actually poor design. It would be better like thisThat way you never have a "blank" (actually null) name to deal with. Beware: nulls can cause all sorts of problems.
Although the compiler will complain about the D, it should be D. The convention is that class names begin with a capital letter. Obviously you have to be consistent: Dog or dog, and don't mix the two.
The capital 'D' of "Dog" there is an error if im not mistaking.
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
The WEB SERVICES and JAX-RS Coursehttps://coderanch.com/t/690789/WEB-SERVICES-JAX-RS