what do curly parentheses do in this case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

what do curly parentheses do in this case

this is a challenge code when I remove the parentheses , an error will happen https://code.sololearn.com/cc15dKL2G35r/?ref=app

9th May 2019, 2:11 AM
ABADA S
ABADA S - avatar
8 Answers
+ 21
The construct '{}' is a compound statement. The compound statement can contain zero or more arbitrary statement. Thus, { { } }, which is a compound statement containing one statement which is a compound statement containing no statement, is legal. • https://www.sololearn.com/Discuss/1020908/?ref=app
9th May 2019, 5:59 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 19
‎‏‪ABADA S‬‏‎ You are welcome! 😊 Also, this is an exam question.
9th May 2019, 6:29 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 19
‎‏‪Sonic One of the questions from the Java SE7 test. A compound statement is a sequence of zero or more statements enclosed in {...}. It is considered to be a single statement. A compound statement is a context. Any variables that are created inside the compound statement are destroyed at the end of it.
9th May 2019, 6:41 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
I think the curly parentheses define a static initialisation block. The error when you remove these maybe because the statements are then not inside any constructor or method and therefore not allowed.
9th May 2019, 3:37 AM
Sonic
Sonic - avatar
+ 6
Danijel Ivanović I think your answer agree with Sonic answer thank you
9th May 2019, 6:22 AM
ABADA S
ABADA S - avatar
+ 5
thanks Sonic your answer is logical when any object is created it will execute this parentheses at the first then call the constructor isn't it?
9th May 2019, 6:16 AM
ABADA S
ABADA S - avatar
+ 5
Danijel Ivanović which exam? 😃
9th May 2019, 6:31 AM
Sonic
Sonic - avatar
+ 1
My point of view inside curly parentheses this block is called Non Static block. When we remove curly brace this two variables become instance variable but type is not define so error will come. If we declare type also error will remove.
10th May 2019, 3:58 AM
Ibney Ali
Ibney Ali - avatar