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

What is static variable with example?

0 Answers  


what is difference between abstraction and interface?

8 Answers   FIC,


If a multi threaded Java program has started numerous number of threads, at any point in time how to know which thread is currently executing/running ?

7 Answers   Accenture, College School Exams Tests, iFlex, NIIT,


What is difference between compatible and incompatible changes in serialization?

1 Answers   Synechron,


whst is encapsulation?when u encpsulate actually while devoloping code?

7 Answers   Amdocs, MGL,






What is a class variable?

0 Answers  


what happens when a thread cannot acquire a lock on an object? : Java thread

0 Answers  


what is struts-config-xml?and its use?

3 Answers  


What is backdrop?

0 Answers   Atos Origin,


For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green  White will have 1 Weight.  Red and Green carry no weights.  Shortest path is the path with less weight when you add up the weights in the path.

0 Answers  


Compare Mutex and Semaphore in java.

0 Answers   Ciena,


How can you make sure that your singleton class will always return single instance in multi-threaded environment?

0 Answers  


Categories