tag:blogger.com,1999:blog-694855878384792308.post1797631812425543368..comments2024-03-21T06:26:49.387-07:00Comments on Java67: What is static in Java? Example Tutorial javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-694855878384792308.post-3404103713278856472016-01-31T23:55:26.097-08:002016-01-31T23:55:26.097-08:00Can we create static block inside static block in ...Can we create static block inside static block in Java??if no then what is the reason behind it.. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-57169592468826187082015-09-25T12:07:35.943-07:002015-09-25T12:07:35.943-07:00Of course static methods are thread safe. The dat...Of course static methods are thread safe. The data you pass in may not be.Mikehttps://www.blogger.com/profile/06723283650058377948noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-66688363063469824452015-08-30T04:22:33.316-07:002015-08-30T04:22:33.316-07:00@Anonymous, because then they become virtual metho...@Anonymous, because then they become virtual methods i.e. they are resolved at run-time, hence they can be overridden. Since kmToMiles() in sub class override same method of parent class you see output from child class, which is "Inside Child class"javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-32981900025154910832015-08-22T10:14:28.104-07:002015-08-22T10:14:28.104-07:00If i remove the static keyword from both kmToMiles...If i remove the static keyword from both kmToMiles() method, the output is "Inside Child class' static method".<br /><br />Why is that? Please explain.<br /> I am new to Java, ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-426111517443082392013-08-05T11:22:51.778-07:002013-08-05T11:22:51.778-07:00Static members in java playing key role.
It shoul...Static members in java playing key role.<br /> It should be used when you don't want to have varying behavior for different objects. <br /><br /><br /><a href="http://efectivejava.blogspot.in/2013/08/when-to-use-static-members-in-java.html" rel="nofollow">http://efectivejava.blogspot.in/2013/08/when-to-use-static-members-in-java.html</a>Anonymoushttps://www.blogger.com/profile/04763758843044031203noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-15922272522151671462013-08-05T08:39:39.529-07:002013-08-05T08:39:39.529-07:00Statics should be used when you don't want to ...Statics should be used when you don't want to have varying behavior for different objects. <br /><br />Statics should be used when data is not instance dependent and for all existing instances of static member you want to apply same state.<br /><br />Statics should not be used at all If they are not actually required as they create dependencies and references to other classes and class loader in JVM and stay in memory for long time. So they are not considered for garbage collection once they are done with current work Instead they are de-referenced with their loading classes as they maintain a reference to static classes.<br />Read more-<br />http://efectivejava.blogspot.in/2013/08/when-to-use-static-members-in-java.htmlFilmiMastihttps://www.blogger.com/profile/11460954154994311304noreply@blogger.com