tag:blogger.com,1999:blog-3832771837877502009.post7165907352976806609..comments2024-03-26T07:39:42.333+05:30Comments on Programming Mitra: Why an outer Java class can’t be staticNaresh Joshihttp://www.blogger.com/profile/01073925481525463593noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3832771837877502009.post-37541454284947546642021-09-09T17:51:34.908+05:302021-09-09T17:51:34.908+05:30This was a lovely blog ppostThis was a lovely blog ppostDylan Weekshttps://www.dylanweeks.com/noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-53715318586954844862016-10-17T10:17:59.226+05:302016-10-17T10:17:59.226+05:30Okay I get it, but still Java creator have not des...Okay I get it, but still Java creator have not designed it in a way, so creating a static class will restrict us from having constructor in it.<br /><br />But in Java 8 we can create static methods (as well default methods) in an interface, So it will serve the same purposeNaresh Joshihttps://www.blogger.com/profile/01073925481525463593noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-71833090332120914182016-10-17T01:59:47.808+05:302016-10-17T01:59:47.808+05:30I understood that your argument was that allowing ...I understood that your argument was that allowing to define a class as static is unnecesary because it doesn't add any value.<br />I was arguing that there is added value in defining a class to only have static methods and no constructor.Neilhttps://www.blogger.com/profile/02139821363235277132noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-42502196908840109612016-10-16T17:46:02.836+05:302016-10-16T17:46:02.836+05:30Neil, actually we can create objects from static c...Neil, actually we can create objects from static classes. Think of static inner classes, we can create objects from static inner classes.<br /><br />Declaring a member static will tell JVM that we are going to access it by using class name and this member does not belongs to any particular objects (instead it will belong to class level object).Naresh Joshihttps://www.blogger.com/profile/01073925481525463593noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-3182157201826855812016-10-16T12:43:01.295+05:302016-10-16T12:43:01.295+05:30A good reason to allow static outer class is to pr...A good reason to allow static outer class is to prevent object construction. Instead we have to use the trick of defining a private constructor.Neilhttps://www.blogger.com/profile/02139821363235277132noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-1534688530503876692016-10-16T12:42:18.677+05:302016-10-16T12:42:18.677+05:30A good reason to allow static outer class is to pr...A good reason to allow static outer class is to prevent object construction. Instead we have to use the trick of defining a private constructor.Neilhttps://www.blogger.com/profile/02139821363235277132noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-68026588766969583842016-10-14T11:03:15.296+05:302016-10-14T11:03:15.296+05:30Dear Aki,
Thanks for your reply
Whenever JVM fin...Dear Aki,<br /><br />Thanks for your reply<br /><br />Whenever JVM finds a class in its execution path it checks whether it is loaded into memory or not, If it is not then JVM loads that class into memory and create a class level object of that class (which is actually an object of java.lang.Class). And JVM does it for first entry of class, for second entry that class level object will already be there.<br /><br />Similar in our case Employee emp = new Employee(); JVM will create two objects one is the class level object other is 'emp' itself, the new Employee()Naresh Joshihttps://www.blogger.com/profile/01073925481525463593noreply@blogger.comtag:blogger.com,1999:blog-3832771837877502009.post-62863720866243212442016-10-14T10:22:26.296+05:302016-10-14T10:22:26.296+05:30Employee emp = new Employee();
How this sentence...Employee emp = new Employee();<br /><br />How this sentence will create 2 object? Could you please elaborate?Akihttps://www.blogger.com/profile/00766347974718517117noreply@blogger.com