Java programming course: 4.6 Interfaces

In the previous lesson we wrote a class to model a zoo visitor. Previous lesson: 4.5 Class to model a zoo visitorCourse contents  Interfaces A Java interface (not to be confused with a user interface) is like a class in that it defines a named type that has a group of related method specifications. In an interface, however, there are no method...

Java programming course: 4.5 Class to model a zoo visitor

In the previous lesson you learnt about keywords this and super. Previous lesson: 4.4 Keywords this and superCourse contents Class to model a zoo visitor To model a zoo visitor let's assume you establish that only three pieces of information are required; their name, email address and the animal they are sponsoring, although they might not be spons...

Java programming course: 4.4 Keywords this and super

 In the previous lesson you wrote a class to model a zookeeper. Previous lesson: 4.3 Class to mode a zookeeperCourse contents Keywords this and super The keyword this is used to refer to the current instance, sometimes known as the receiver object. You have previously used it when overloading constructors in order to delegate to a different co...

Java programming course: 4.3 Class to model a zookeeper

In the previous lesson you learnt about the Object class: Previous lesson: 4.2 The Object classCourse contents Class to model a zookeeper The zoo will of course require a number of zookeepers to help look after the animals, so you will now develop a ZooKeeper class. Just as you did with the Animal class, you need to think about the attributes and m...

Java programming course: 4.2 The Object class

In the previous lesson we covered packages and imports. Previous lesson: 4.1 PackagesCourse contents  The Object class You saw earlier that any class can extend (i.e., inherit from) any other class, and this can be another class written by you or someone else, or a Java supplied class. In fact, every class always inherits from a special Java s...

Java programming course: 4.1 Packages, the Object class, and interfaces

In the previous lesson we tidied up the Animal constructors. Previous lesson 3.6: Tidying up the Animal constructorsCourse contents Packages, the Object class, and interfaces Packages allow you to partition your classes into sets of logical groups, and enables you to protect parts of your application from other parts. The Object class provides the ...

Java programming course: 3.6 Tidying up the Animal constructors

In the previous lesson we looked at abstract classes and methods. Previous lesson 3.5 Abstract classes and methodsCourse contents  Tidying up the Animal constructors Since making the Animal class abstract the only constructor that ever gets invoked within Animal is the one requiring three arguments, which is called by its subclasses using the ...

Java programming course: 3.5 Abstract classes and methods

In the previous lesson you learnt about overriding. Previous lesson: 3.4 OverridingCourse contents Abstract classes and methods Now that you have created three subclasses of Animal you might like to consider what is meant by "animal": does it ever make sense to instantiate an Animal object that isn't a specific type of animal? It seems natural to t...

Java programming course: 3.4 Overriding

 In the previous lesson you learnt about inheritance. Lesson 3.3 InheritanceCourse contents Overriding The zoo would like to know which animal types are endangered, even though most types in the zoo are not. Add the following method within the Animal class:   public boolean isEndangered() { return false;} Note that for getter methods that...

Java programming course: 3.3 Inheritance

In the previous lesson you learnt about overloading. Lesson 3.2 OverloadingCourse contents  Inheritance It was mentioned earlier that there is currently no obvious way of specifying what type of animal is being created. You might guess that Bruno could be a dog or that Tiddles could be a cat, but there is no guarantee of this. For the zoo appl...