Is it possible to write method inside method
Answers were Sorted based on User's Feedback
Answer / divya
no,it's not possible to write method inside a method.it
will gives an error illigal starts of expression
Is This Answer Correct ? | 17 Yes | 4 No |
Answer / janeesh
it is possible to write a method inside a method by using
method local inner classes.
Eg:
class Outer {
public void display() {
System.out.println("This is outerclass method.");
class Inner{
public void displayInner()
{
System.out.println("innerclass method");
}
}
Inner objC = new Inner();
objC.displayInner();
}
}
class MethodeInsideMethod {
public static void main(String[] args) {
Outer objC = new Outer();
objC.display();
}
}
Output:
This is outerclass method.
innerclass method
Is This Answer Correct ? | 11 Yes | 5 No |
Can we use different return types for methods when overridden?
What is extension method in java?
Explain the significance of listiterator.
What is the full meaning of java?
Can a class be defined inside an interface?
Explain heap sort?
what is overloading and overriding with example?
What is operator overloading. Is it is supported in java?
What are the advantages of passing this into a method instead of the current class object itself?
What are the differences between abstract class and interface?
What happens if main method is not static?
What is casting?