This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes methods in methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "methods in methods" Watch "methods in methods" New topic

methods in methods

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

may i know why this does not this program get compiled?

public class HelloName{
public static void main(String args[]){

void abc(){ }

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24190

Because you're trying to define a method inside another method, something the Java language does not allow? Some folks recently had a discussion about this very thing here; check it out if you're interested.

[Jess in Action][AskingGoodQuestions]
It is sorta covered in the JavaRanch Style Guide.
subject: methods in methods
It's not a secret anymore!