+ 2
Why no "new" keyword needed when creating object in LocalDateTime in Java?
Hi quck question. Why no "new" keyword needed when creating object in LocalDateTime? exp: LocalDateTime rightNow = LocalDateTime.now(); System.out.println("current datetime : " + rightNow); But if we create an new Object of the class or object of StringBuilder we need to use new keyword exp ClassName refName = new Classname(); or StringBuilder sb = new StringBuilder(); Thnaks in advance
7 Respostas
+ 9
This should help
https://code.sololearn.com/cgSjEId598Ca/?ref=app
+ 8
LocalDateTime has a static method called now() that returns a LocalDateTime Object
+ 5
You're welcome Roman
+ 1
Thank you, but it didn't answer my question
+ 1
Yerucham thank you, understood!!!
+ 1
new is a special keyword and when we use ' new' it do the following 3 steps
1. reads the class
2.invokes the constructors.
3.allocates the memory.
+ 1
so localdatetime needs no new