Is it possible to write method inside method

Answers were Sorted based on User's Feedback



Is it possible to write method inside method..

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

Is it possible to write method inside method..

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

Is it possible to write method inside method..

Answer / mitul

Answer #2 is correct

Is This Answer Correct ?    7 Yes 1 No

Is it possible to write method inside method..

Answer / umesh

Answer #2 is wrong

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More Core Java Interview Questions

Can we use different return types for methods when overridden?

0 Answers  


What is extension method in java?

0 Answers  


Explain the significance of listiterator.

0 Answers  


What is the full meaning of java?

0 Answers  


Can a class be defined inside an interface?

0 Answers  






Explain heap sort?

0 Answers   Flextronics,


what is overloading and overriding with example?

2 Answers   CMC,


What is operator overloading. Is it is supported in java?

0 Answers  


What are the advantages of passing this into a method instead of the current class object itself?

0 Answers  


What are the differences between abstract class and interface?

0 Answers  


What happens if main method is not static?

0 Answers  


What is casting?

5 Answers  


Categories