answersLogoWhite

0


Best Answer

public void test(int arg1, int arg2) throws Exception{

.......

}

Above is a typical declaration of a user defined method in java.

The first word public defines the access modifier for the method. you can use public or private.

the second word defines the return type of the method. a void represents no return value. you can have int, String, float etc...

third word is the method name. You can have anything except keywords in this

The values inside the parenthesis are the arguments. A method can take any number of arguments

The throws declaration signifies that this method may throw exceptions. The calling method should have code to handle them.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Assuming you don't have access to the source code of the "predefined class", you can still create an inherited class, and add methods to that. Note, however, that an inherited class will not be able to directly access private members of the parent class.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

All methods you write in your classes are user defined methods.

ex:

public String getName(){

return "Rocky";

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is it possible in java that using user defined methods in predefined classes?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can userdefined exception have two methods in it?

Yes a user defined exception can have any number of methods in it. A user defined exception is nothing but a Java class created for a specific purpose. Just like ordinary Java classes, you can have any number of methods in it...


What makes up a Java class?

Fields and methods. Fields are variables defined at the class level, i.e., they are available for all methods. Methods are the equivalent of functions / procedures, but they are defined for a specific class.


Why all methods should be written in classes in java?

A Java class is expected to have all functions defined. The purpose of defining the methods is to decide on its expected functionality and behavior. Only in case of Interfaces we declare methods but leave the method definitions to the implementing classes.


Are binary search and linear search already defined method in some class in java and what class is this?

You can check out the Arrays.binarySearch group of methods for searching sorted arrays. There is no predefined linear search for arrays, probably because it is trivially easy to implement. If you have some other data structure to search, the Collections.binarySearch methods should work for you. Most collections can also be converted to a List representation, which has a predefined indexOf method for linear searching.


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"

Related questions

What is the use of api in java?

The API is a reference for all predefined classes provided by the java language. This will allow the programmer to utilize the classes into their programs. The API provides packages, classes, methods, constants, etc.


What is the difference between predefined functions and user defined functions?

What is the difference between predefined function and user defined functions


Can userdefined exception have two methods in it?

Yes a user defined exception can have any number of methods in it. A user defined exception is nothing but a Java class created for a specific purpose. Just like ordinary Java classes, you can have any number of methods in it...


What makes up a Java class?

Fields and methods. Fields are variables defined at the class level, i.e., they are available for all methods. Methods are the equivalent of functions / procedures, but they are defined for a specific class.


Why all methods should be written in classes in java?

A Java class is expected to have all functions defined. The purpose of defining the methods is to decide on its expected functionality and behavior. Only in case of Interfaces we declare methods but leave the method definitions to the implementing classes.


What is the difference abstract class and interface?

They are very different. An abstract class is a class that represents an abstract concept (Google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)


Are binary search and linear search already defined method in some class in java and what class is this?

You can check out the Arrays.binarySearch group of methods for searching sorted arrays. There is no predefined linear search for arrays, probably because it is trivially easy to implement. If you have some other data structure to search, the Collections.binarySearch methods should work for you. Most collections can also be converted to a List representation, which has a predefined indexOf method for linear searching.


Why keywords in java important?

In the Java programming language, a keyword is one of 53 reserved words that have a predefined meaning in the language; because of this, programmers cannot use keywords as names for variables, methods, classes, or as any other identifier.


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"


Examples of codes in java?

public class Hello{//opens the classpublic static void main(String args[]){//opens the main methodSystem.out.println("Hello World");}//closes the main method}//closes the classNote: The compiler all the sentences that have "//" before them.


What are factory methods in java?

A factory class is any class which is used to create instances of other classes. The methods which create those classes are the factory methods. For example, the BorderFactory class has a variety of methods for creating instances of the different types of the Border classes. BorderFactory.createEmptyBorder(); BorderFactory.createEtchedBorder(); ...


What is different between function and object in java?

a variable holds a single type of literal. i.e. 1, bat, 345. A object is a instance of a class created by the a programmer with a set of methods which preforms certain task depending what methods have been defined. int a = 4; // a would be the variable Car b = new Car();// b is an object b.carGo();// this is an method in the object car created below. class Car(){ void carGo(){ car moves; } }