Abstract Methods and Classes

By Raul Rios

Abstract classes are usually meant to share pieces of implementation and to be extended:

Abstract methods are methods declared without an implementation (no body and semicolon at the end).

An important thing to remember about abstract methods is that if a class has one or more abstract methods then ..Continue Reading

Polymorphism

By Raul Rios

In order to try and explain the important topic of polymorphism in Java, I will use the following class hierarchy as an example:

Given this class hierarchy, what could we say about MobileDevice? It’s a descendant from Device (and implicitly from Object) so we could say: A MobileDevice is a ..Continue Reading

Inheritance

By Raul Rios

Excluding Object, which has no superclass, every Java class has one and only one direct superclass. That superclass is implicitly Object if no other superclass is specified using the reserved word extends. If class B extends from class A, then the subclass B inherits the accessible members from the superclass A. ..Continue Reading

Nested Classes

By Raul Rios

A nested class is a class declared within another class. It’s a member of the enclosing class and so can be declared private, public, protected or default. A nested class can be static, inner, local or anonymous. The following sections try to clarify these sometimes-confusing terms. The two key things you must know ..Continue Reading

Access Control Modifiers

By Raul Rios

Access control modifiers let you specify what types (mainly classes) and members of those types are accessible from other types and members, in order to get a proper encapsulation. The following table summarizes the meaning of the four (really three) available access control modifiers in Java. You can read the content of ..Continue Reading

Constructors

By Raul Rios

Constructors are used to create objects (instances of a class). They are declared like methods but always using the name of the class and having no return type. Be careful about tricky questions like this: Is the following an example of a valid constructor? Does it compile?

A method name ..Continue Reading

Methods

By Raul Rios

The four things about methods that you need to grasp well  for the exam are: Arguments are always passed by value Varargs The return value Method overloading Method arguments are always passed by value, which means that any changes to the values of the arguments exist only within the scope ..Continue Reading

Loops: break and continue

By Raul Rios

There are two kinds of breaks for a loop: The unlabeled break: break; The labeled break: break label; What you must know about the unlabeled break is: It terminates the innermost switch, for, while, or do-while You get a compiler error if not one of these loops encloses the break ..Continue Reading

Loops

By Raul Rios

There are four kinds of loops in Java: The while loop The do-while loop The for loop The for-each loop (enhanced for) The while loop It’s executed while the given expression is evaluated to true:

If the expression is initially false, the statement or block is never executed. The ..Continue Reading

Multi-Dimensional Arrays

By Raul Rios

Multi-Dimensional arrays are arrays whose elements are themselves arrays. The same as One-Dimensional arrays there are different ways of declaring them. Only one of these ways is the preferred way, but for the purpose of the exam you must know all the valid ways. Let’s see them with some examples:

Once you ..Continue Reading