Clarification
about Some Java Questions
1 A static method can called only static field and another static method but MAIN() is also static and we can call non-static method and fields inside MAIN()?Justify it? Misconception. A static method can call non-static methods also, but it needs an instance variable to invoke the method. Lets say if a static method could invoke a non-static method without a reference variable. In this case it woud be impossible for the compiler or the VM to resolve on which instance the method has to be invoked on, since static context is not coupled to instances. 2 How many type of modifier a class can have and what is the default modofier? Public and package. It does not make sense to make a outer class private or protected, does it? 3 Why constructor can't be abstract or static?
Well it can't be static since as I mentioned before static context is not coupled to instances and the raison d'etre of a constructor is to create instances. 4 Why a java file can't have more then one public class? This is a small optimization technique to make the life
of the compiler and the VM easier. Imagine if you could declare several
Java Tips by : Schizophrenicpsychosis
Related:
Java Certification, Programming, JavaBean and Object Oriented Reference Books Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|