Justify your answer that you can't define a method inside another method in java, if you can then how?



Justify your answer that you can't define a method inside another method in java, if you can th..

Answer / Preet Banga

In Java, it is not possible to define a method inside another method. Methods are declared outside of methods and classes. If one tries to declare a method within another method, the compiler would produce an error.nHowever, you can achieve similar functionality using lambda expressions or anonymous inner classes in Java 8 or later.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Can there be an abstract method without an abstract class?

1 Answers  


what is difference between method overloading & method overridding with example?

4 Answers   IBM,


Does .length start 0 java?

1 Answers  


How to reverse string in java?

1 Answers  


public class Test { public static void main(String ar[]) { Integer a = 10; Integer b =10; Integer c = 145; Integer d = 145; System.out.println(a==b); System.out.println(c==d); } }

7 Answers   iGate,


How can we create a synchronized collection from given collection?

1 Answers  


Explain the differences between public, private, protected and static?

4 Answers  


How do I run java on windows?

1 Answers  


How many times garbage collector will invoke an object?s finalize() method?

4 Answers  


What is the default size of arraylist in java?

1 Answers  


what is the collable collections in java?

2 Answers   Persistent,


What are the different types of multitasking?

1 Answers  


Categories