Static
We use the static keyword when we want all the objects to share a single variable. In this program we make 3 new objects that all share the static int…
We use the static keyword when we want all the objects to share a single variable. In this program we make 3 new objects that all share the static int…
Outputs: emma xml 40 george php 100 bernard excel 76 matthew perl 19 .. and now to a range of constants emma xml 40 george php 100 bernard excel 76…
Below we have 3 objects (aka enumerations in this case), and they each have their own set of variables. One for description, and one for year. Enumerations are effectively objects…
A class doesn't just need to contain methods and variables, it can also contain references to object. This is known as composition. Any time you want to turn an object…
Any time that you need a string representation of an object, we use toString. Outputs: The contructor for this is 5/6/7 Since 'this' is used, in the system.out.printf statement, it…
A constructor is a method with the same name of it's class. The constructor is automatically called when an object is created from the class. A class file can have…
Controlling different variables in different classes. In the below class, the declaration of; private int hour; private int minute; private int second; As private, only the methods within the cat.class…
Outputs: 14:15:20 2:15:20 pm
Outputs: 00:00:00 14:15:20
Sometimes you want to build a method and you don't know how many arguments it needs. For example, a method that averages a bunch of numbers. This example shows how…