What is a method?

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....
Explain how to create instance of a class
Explain how to create instance of a class - Java supports 3 ways of creating instances - By using new operator – Ex : Product prodMouse = new Product();....
What is an abstract class?
What is an abstract class? - A class with one of more abstract methods is called an Abstract class....
Post your comment