This expresses Java's feature of object-oriented languages we call
inheritance. It expresses the "IS_A" relationship.
First of all, we see:
public class Dog extends Pet
which means that whatever a Pet does, a Dog does -- and more!
There are several ways to describe this; Dog is a
child class or
subclass of Pet, while Pet is the
parent or
superclass of Dog (in C#, we also call Pet the
base class, which is a keyword in C#). In either case, Dog IS_A Pet.
I want to make sure you know what a
constructor is. A constructor is a special type of method used when you're initializing a new object instance. Your Dog class has a constructor; it's the one with no return type that you emphasized.
When you're inside a constructor, you can call a specific constructor for the parent class, so that the parent class's data gets initialized as well. In this case, calling super(dogName) tells the compiler to bind the call to the Pet(String) constructor (we know this because the superclass of Dog is Pet, and the dogName variable is typed String).
To get the name of the pet, you call the Pet class's getName() function. Because the Pet class defines this function, and its data, you don't need to do so in the Dog class. This is another feature of object-oriented programming, called
encapsulation. Encapsulation allows us to treat objects like a black box; we don't need to know anything about how the data is stored internally, just how to access it. In this case, the Pet class encapsulates the "name" property of the Pet object and all of its descendant classes.
You can implement your own Name property in the Dog class also, by adding an additional variable and the getName() function to the Dog class; IIRC, all methods in Java are virtual by default. But that's inefficient - the Pet class already defines a way to get to that data.