How do you create a method in java?



How do you create a method in java?..

Answer / Shashi Kant Srivastava

"In Java, a method is created using the keyword 'public' followed by the return type of the method, the method name, and parentheses containing any parameters. The method body is enclosed within curly braces. Here's an example of a simple method that returns a string:

```
public String myMethod() {
return "Hello, World!";
}
```"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

strings in java are objects.why?

2 Answers  


What do you mean by aggregation?

2 Answers  


What is the public field modifier?

1 Answers  


Explain the available thread states in a high-level?

1 Answers  


What are reference variables in java?

1 Answers  


Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.

1 Answers  


What is linkedlist in java?

1 Answers  


What is instance synchronization?

1 Answers  


What is difference between path and classpath?

1 Answers  


Why do we create public static method in java?

1 Answers  


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

1 Answers  


Which number is denoted by leading zero in java?

1 Answers  


Categories