Types of Methods

Java Predefined & User defined Methods, Java String Methods, Java Number Methods, Java Array Methods and Java Character Methods. Java User defined methods with return a value, User defined methods without return any value, and Java Static & Non-static Methods.
Post Reply
Posts: 47
Joined: Mon Dec 31, 2018 6:40 am

Types of Methods

Post by sekhar » Sat Jan 05, 2019 11:35 am

Explain and How Many Types of Methods?

Posts: 85
Joined: Thu Jan 03, 2019 3:58 am

Re: Types of Methods

Post by srini » Thu Jan 10, 2019 3:44 am

Java has three different types of methods:
1. Static methods: A static method is a method that can be called and executed without creating an object. In general, static methods are used to create instance methods.
Static method can be invoked directly via class name i.e.; we don't have to create an object for a class in order to initiate static method.

2. Instance methods: These methods act upon the instance variables of a class. Instance methods are being invoked with below syntax


Instance methods are classified into two types:

a. Accessor methods: These are the methods which read the instance variables i.e.; just go access the instance variables data. Generally these methods are named by prefixing with "get".

b. Mutator method: These are the methods, which not only read the instance variables but also modify the data. Generally these methods are named by prefixing with "set".

3. Factory methods: A factory method is a method that returns an object to the class to which it belongs. All factory methods are static methods.

Eg: NumberFormat obj = NumberFormat.getNumberInstance();

Post Reply

Return to “Java Methods”