0% found this document useful (0 votes)
2 views11 pages

Java Methods: Types, Examples & Practice

The document provides an overview of Java methods, explaining their purpose, types, and importance in programming. It includes examples of void and return-type methods, as well as real-life applications like making tea and a mini project on generating a shopping bill. Additionally, it lists practice questions to reinforce understanding of method implementation.

Uploaded by

mssdkkl
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Java Methods: Types, Examples & Practice

The document provides an overview of Java methods, explaining their purpose, types, and importance in programming. It includes examples of void and return-type methods, as well as real-life applications like making tea and a mini project on generating a shopping bill. Additionally, it lists practice questions to reinforce understanding of method implementation.

Uploaded by

mssdkkl
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Java Methods

Explanation • Examples • Real-Life


Projects • Practice Questions
What is a Method?
• A method is a block of code that performs a
task.
• Methods help in reusability and clean code.
• You must call a method to execute it.
Why Methods?
• Avoid repetition (DRY principle)
• Better organization
• Easier debugging
• Reusability
• Clean structure
Types of Methods
1. void methods (no return)
2. return-type methods
3. methods with parameters
4. methods without parameters
Example: void method
void sayHello() {
[Link]("Hello!");
}
Call: sayHello();
Example: method with return
• int add(int a, int b) {
• return a + b;
• }
• Call: int x = add(5, 10);
Real-Life Example: Making Tea
makeTea() method calls:
• boilWater()
• addTeaPowder()
• addMilk()
• addSugar()
• stirTea()
Mini Project: Shopping Bill
Methods:
• displayProducts()
• getPrice()
• generateBill()
Shows real-world usage.
Important Rules
• Method must be called
• Meaningful names
• Return only one value
• main() is also a method
Practice Questions (1–5)
1. Method to check even/odd
2. Method to find greatest of 3 numbers
3. Method for multiplication table
4. Method to count vowels in string
5. Method to sum array elements
Practice Questions (6–10)
6. Method to find max in array
7. Method to print star pattern
8. Method to calculate GST bill
9. Method to transpose 2D array
10. Menu-driven program using methods

You might also like