All Flashcards
What is a non-void method?
A method that returns a value of a specific data type.
What is a return type?
The data type of the value returned by a non-void method.
What is the purpose of the return statement?
To send a value back to the caller and terminate the method's execution.
What is a parameter list?
Input values the method needs to do its job (optional).
What is the significance of the static keyword in a method header?
Indicates the method belongs to the class itself, not an object.
What is the purpose of access modifiers like public?
Specifies the accessibility of the method from other parts of the code.
What is unreachable code?
Code that will never execute because it is placed after a return statement.
Define a boolean method.
A method that returns a boolean value (true or false).
What is a String method?
A method that returns a String value.
What is a reference type?
A data type that refers to an object (e.g., String, ArrayList).
Why must the return type in the method header match the type of the returned value?
To ensure type safety and prevent compile-time errors.
What happens if a non-void method does not have a return statement?
It causes a compile-time error.
Why is it important to trace code with non-void methods?
To understand the flow of execution and predict the returned value.
Explain the concept of returning a reference type.
Returning a reference type means returning the memory address of an object.
What is the significance of naming boolean methods with is?
It improves code readability and indicates that the method checks a condition.
Why are non-void methods useful?
They allow methods to perform calculations or retrieve values and pass them back for use elsewhere in the program.
What is the purpose of the return statement?
The return statement is crucial for returning a value and stopping the method's execution.
What is a common mistake to avoid when using non-void methods?
Mismatched return types, unreachable code, and forgetting to return.
What is the difference between void and non-void methods?
Void methods do not return a value, while non-void methods return a value of a specific data type.
How does the return statement affect the execution of the method?
The method stops executing after a return statement.
How are non-void methods used in mathematical calculations?
To perform calculations and return the result (e.g., calculating the area of a circle).
How are non-void methods used in data validation?
To check if data meets certain criteria and return a boolean value (e.g., checking if a number is within a specific range).
How are non-void methods used in string manipulation?
To create or modify strings and return the result (e.g., reversing a string or creating a greeting).
How are non-void methods used in object creation?
To create new objects and return a reference to the object (e.g., creating an ArrayList).
How are non-void methods used in game development?
To calculate scores, determine game states (win/lose), and manipulate game objects.
How are non-void methods used in financial applications?
To calculate interest rates, loan payments, and investment returns.
How are non-void methods used in scientific simulations?
To perform complex calculations and return simulation results.
How are non-void methods used in web development?
To process user input, generate dynamic content, and interact with databases.
How are non-void methods used in mobile app development?
To handle user interactions, manage data, and perform background tasks.
How are non-void methods used in AI and machine learning?
To implement algorithms, calculate predictions, and evaluate model performance.