This is regarding java. This is question asked in a interview.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#40222 that contains the specifications of the The JavaTM Virtual Machine Specification, doesn’t seem to give limits.
It probably was a trick question.
I would say that there are limits. Probably you can’t have a
.javafile 4gb big, so extrapolating from that number you can say that there are probably less than some hundred million classes that can be inner classes of a class.If we consider this 4gb file limit an hard limit, and we say that we want all the inner classes to be 6 character (AZaz09) long,
It’s 14 characters.
And it is correct to write:
Now, 4gb / 14 characters = 300 million inner classes. So I’m quite sure the maximum number is < 300 million inner classes.
Now, if you are REALLY interested on hard numbers, tomorrow I’ll make a program able to create some hundred million inner classes and I’ll try to see on my computer with Windows Java 1.7 64 bits how much big a source file can be.
I’ll add that the right response would be something similar “is it really important if it’s 100 or 1000 or one million? How many inner classes would you put in a class? In years of programming I haven’t ever put more than 3 or 4 in a class. But perhaps your programmers love to write single class files long more than 10000 lines of code.”
And taking from the hourse mouth (the Sun Java site):
Files longer than 2000 lines are cumbersome and should be avoided.Clearly it is only a recommendation.