What is a method? Provide several signatures of the methods

What is a method? Provide several signatures of the methods

A java method is a set of statements to perform a task. A method is placed in a class.

Signatures of methods: The name of the method, return type and the number of parameters comprise the method signature.

A method can have the following elements in it signature:

- Access specifier – public, private, protected etc. (Not mandatory)
- Access modifier – static, synchronized etc. (Not mandatory)
- Return type - void, int, String etc. (Mandatory)
- Method name – show() (Mandatory)
- With or without parameters – (int number, String name); (parenthesis are mandatory)

Example:
void showResult () { }
public double getSalary(double basicSalary) { }
public static void finalValue() { }
public static void getStateName(String city ) { }
Difference between instance variable and a class variable
Difference between instance variable and a class variable - An instance variable is a variable which has one copy per object / instance. That means every object will have one copy of it...
Explain how to create instance of a class by giving an example
How to create instance of a class - Java supports 3 ways of creating instances...
Define an abstract class. Explain its purpose
Define an abstract class - A class with one of more abstract methods is called an Abstract class...
Post your comment