During runtime (execution), our program sometimes encounter unforeseen errors. For example, our program may be in the middle of reading a file from disk when the disk crashed and we can no longer proceed to read the file. In unforeseen situations like this, the JVM would notify our program of the error by throwing an Exception object describing the error.
In our previous article about polymorphism, we gave an example of a
Shape class inherited by three subclasses,
Circle. With polymorphism, a variable of type
Shape can reference an object of any of the 3 subclasses.
Previously, we said that inheritance is a feature of Java (and many object-oriented languages) that allows us to inherit variables and methods from another class. Inheritance denotes an “is a” relationship between classes. For example, if class
Square inherits class
Rectangle, then technically, an object of
Square is an object of
Rectangle because both classes have the same methods we can call.
In the previous article, we covered class inheritance in Java, which is a feature to copy methods and member variables of another class into our class. We gave an example that since a square is a rectangle, the
Square class can inherit the
Rectangle class and get the
area() for free.
In this article, we are going to cover one famous feature of Java, that is inheritance. If you ask someone, what is OOP? They will no doubt say something about inheritance and class hierarchy. Of course, this is just one feature of object-oriented concepts, but it’s an important one. We’re going to find out what it is!
In our earlier article Classes and Objects, we showed how to write a constructor for a simple class. In this article, we are going to dive deeper into the topic and show how constructors work and consider different types of constructors.
Previously we covered the basics of writing classes and method in this article. Because object-oriented-programming (OOP) concepts are such an important topic in Java, we’re coming back to covering the rich OOP features offered by Java! In this article we are going to start slow and cover the simple topic of method overloading.
The following table is a list all operators and their precedence (order of evaluation). Operators with lower level are performed before higher level.
In the previous article, we covered
switch statements that are used to selectively execute certain portion of our code based on certain conditions. In this article, we are going to cover another type of control construct called loops.
In the previous article, we covered boolean expressions, which have a value of
false, and logical operators that work on boolean values. This article covers how to use boolean expressions (or conditions) to decide what portion of our program to execute. For example, if a certain condition is true, our program should do this; otherwise is should do something else.