Method calls inside a Java class

前端 未结 8 2335
难免孤独
难免孤独 2020-11-28 15:31

I was setting out to write a piece of code today in Eclipse, and I started out like so:

public class MyClass {
    System.currentTimeMillis();
}
         


        
8条回答
  •  醉话见心
    2020-11-28 16:23

    You dont get the error with the line

    long time = System.currentTimeMillis();
    

    because you are specifying a private variable inside the class (long time) and setting them to a default value (System.currentTimeMillis()) so when you make a new instance of the class MyClass, the variable is being instantiated.

    calling only System.currentTimeMillis() just has nosense, because you arent doing nothin' (neither having a context or assigning the value to a private variable)

提交回复
热议问题