Use of setters and getters is one way.
You are declaring name and age as protected. So if the dogList class and dog class are in the same java package you can just access the name and age using,
d.name
d.age
However please check your dog class. Your name variable is declared as 'name', but...