Experienced Java/J2ee Interview questions asked by MNC.
1. Why main() in java is declared as public static void main? What if the main method is declared as
private?
Ans : Because, every program start exucution from main function.The static method can directly call without createing the object of the class.So, before createing object the main function runs and then it creates object.
And, public in main method due to access by JVM. If the method is private then JVM cannot call that function.The program will compile but never run.It show the message "Main method not public."
2.What is Externalizable?
Ans : This interface is used for serialization.To save the state of an object in file. It provides two method
readExternal() and writeExternal().
3.What modifiers are allowed for methods in an Interface?
Ans : abstract and public
4.What are the different identifier states of a Thread?
Ans :
R- Running or Runnable
S- Suspended
MS- Thread Suspended on Moniter lock
MW- Thread waiting on moniter
CW- Thread waiting on condition variable
5.What are some alternatives to inheritance?
Ans : Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
6.Why isn’t there operator overloading?
Ans : Because C++ has proven by example that operator overloading makes code almost impossible to maintain.
7.What does it mean that a method or field is “static”?
Ans : Static method or field are member of class.They do not need any object for call or access . We can directly call the static method and fields without using the object.
1. Why main() in java is declared as public static void main? What if the main method is declared as
private?
Ans : Because, every program start exucution from main function.The static method can directly call without createing the object of the class.So, before createing object the main function runs and then it creates object.
And, public in main method due to access by JVM. If the method is private then JVM cannot call that function.The program will compile but never run.It show the message "Main method not public."
2.What is Externalizable?
Ans : This interface is used for serialization.To save the state of an object in file. It provides two method
readExternal() and writeExternal().
3.What modifiers are allowed for methods in an Interface?
Ans : abstract and public
4.What are the different identifier states of a Thread?
Ans :
R- Running or Runnable
S- Suspended
MS- Thread Suspended on Moniter lock
MW- Thread waiting on moniter
CW- Thread waiting on condition variable
5.What are some alternatives to inheritance?
Ans : Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
6.Why isn’t there operator overloading?
Ans : Because C++ has proven by example that operator overloading makes code almost impossible to maintain.
7.What does it mean that a method or field is “static”?
Ans : Static method or field are member of class.They do not need any object for call or access . We can directly call the static method and fields without using the object.
All the Best for Interview !!!
You can share your interview experience with asked questions and answers for publishing on this blog.
Follow for more details on Google+ and @Facebook!!!
Find More Questions & Answers Below.
You can share your interview experience with asked questions and answers for publishing on this blog.
Follow for more details on Google+ and @Facebook!!!
Find More Questions & Answers Below.
- Experience Java Interview Questions & Answers.
- Birla Soft Interview questions for Java 2-4 Year experience.
- Accenture Interview questions for Java 3-8 Year experience.
- Experienced Interview questions by Tavant Technologies.
- CGI Interview questions for Java 3-8 Year experience.
- Capgemini Java Interview questions for 3-8 Year experience.
- IBM Java Interview questions for 3-8 Year Experience.
- SapientNitro Interview questions for Java 2-6 Year experience.
Best Java development service in houston @ Affordable java developer service in USA
ReplyDelete