Escolar Documentos
Profissional Documentos
Cultura Documentos
Create a Method
4
A method must be declared within a
class. It is defined with the name of the
method, followed by parentheses (). Java
provides some pre-defined methods,
such as System.out.println(), but you can
also create your own methods to
perform certain actions:
Example
Create a method inside MyClass:
In case of method overloading, parameter must be different. In case of method overriding, parameter must be same.
Method overloading is the example of compile time Method overriding is the example of run time
polymorphism. polymorphism.
method overloading can't be performed by changing return
type of the method only. Return type can be same or different Return type must be same or covariant in method
in method overloading. But you must have to change the overriding.
parameter.
boolean Boolean
char Character