Here's a Question.....!
....
........
Define a function/method with a suitable example.
.......
....
No Spams!!
Answers
Functions are group of statements containing executable codes that represent the behavior aspect of an object.There are different types of functions used to perform specific task.
They are divided into two categories
1. Library or in-built functions
example- Math.max(), length()
2.User defined functions
example- void sum()
hope it helps!!!
please mark me as the Brainliest
In C/C++, these are known as 'Functions'.
Explanation:
Short note on method() in Java:
(i) Methods describe behavior of an object.
(ii) Collection of statements to process specific tasks and return responses to the user.
(iii) Method is included in the class.
(iv) 'main' method is the first method which the JVM executes.
Sample Program:
(i)
public class Brainly
{
static void Hell()
{
System.out.println("Welcome to brainly.in");
}
public static void main(String args[])
{
Hell();
}
}
Output:
Welcome to brainly.in
(2)
class Demo
{
public static void main(String args[])
{
Brainly o = new Brainly();
jBrainly k = new Quora();
o.display();
k.display();
}
}
class Brainly
{
public void display()
{
System.out.println("Welcome to brainly.in);
}
}
class Quora extends Brainly
{
public void display()
{
System.out.println("Welcome to Quora.in");
}
Output:
Welcome to brainly.in
Welcome to Quora.in
Hope it helps!