开发者

Is this valid Java code? My teacher claims it is, but I'm really not so sure [duplicate]

This question already has answers here: 开发者_开发问答 Why is this Java code in curly braces ({}) outside of a method? (3 answers) Closed 9 years ago.

Granted he didn't show us actual code here, just mentioned it, I found it extremely bizarre.

For example, according to what he said this is valid Java:

public class Person
{
    String Name;
    int Age;

    {
        //These two braces just chilling together - VALID? :O
    }
}


Yes - it's the instance initializer. You can also use it along with anonymous subclasses for Double-Brace Initialization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜