What happen if we write many curly braces in main method and write println method inside it .program will compile or not?

Showing Answers 1 - 16 of 16 Answers

shivalak

  • May 23rd, 2006
 

Hi,
   You can have any number of curly braces inside any(main as well as other)
functions but each and every brace should have matching close brace.
Also you can have any number of semi colons(;)
The following program compiles and print the message "Hi Guest"
public class Test {
    public static void main(String[] args) {
    {}{}{}{}{}{}{} System.out.println("Hi Guest");;;;;;;;;;;;{
    }
 }
}

  Was this answer useful?  Yes

richa

  • May 25th, 2006
 

It successfully compiled and output is Hi Guest.

  Was this answer useful?  Yes

satheesh

  • Jun 7th, 2006
 

It works fine. But what happens in the flow. What is the effect of having this type of code.Whats the side effects

  Was this answer useful?  Yes

CHANDRA SEKHAR JONNALAGADDA

  • Jun 13th, 2006
 

hi

 

              Friends, u create so many curly braces but no problem. programs execution  is succesfully.

                        chandra sekhar jonnalagadda 

  Was this answer useful?  Yes

Amit Patil

  • Sep 19th, 2007
 

Program will run fine as long as there are matching closing braces in main method or any method.

  Was this answer useful?  Yes

public class braces
{
public static void main(String args[])
{
{}
{
{
System.out.println("braces");
}
}
}
}
The program will compile and run fine,If there is a matching right hand braces for every left hand braces.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions