Java by i Code Academy
Name of the parent class (superclass) and keyword extends
Note: A subclass can only extend one parent at a time
Interfaces
-Separated by commas if there are multiple interfaces that need to be implemented
Class Body
-begins with { and ends with }
Objects
In java, an object is an instance of a class. It is created by the program to interact with everything else through the use of methods. Because of that, a program can carry out multiple objectives such as animation, GUI implementation and information management between a sender and a receiver.
After an object finished its objectives, its resources are again used by other objects.
Methods
We have already introduced ourselves with methods in the previous chapters. As we know, a method is the same as a function in other programming languages like C. It is used to perform specific tasks like calculations and manipulation. Here is an example of a method:
public void getAverage (float exam1, float exam2, float exam3){
float average, ex1, ex2, ex3;
average = (ex1 + ex2 + ex3)/3;
System.out.println(âThe average is: â + average + â%.â);
}
In a method, the only components needed are the name of the method, the return type, the parameters if there are any, and of course, the body itself.
However, there are some components that can also be added such as modifiers and exception list. Modifiers are important in methods so that data access can be secure and there will be no mishandling of fragile information. Exception lists are also important since they are used in handling runtime errors. More on exception lists to be discussed in the following chapters.
In a method declaration, it is important to always have the method signature. The method signature is the name of the method and its parameter types.
Here is an example:
getAverage(float, float, float)