Most frequently Asked and Important Interview Questions
Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
2. What is a Class ?
A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.
3. What is a Methods ?
A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
4. What is an Instance Variables ?
Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.
5. Is Java Case Sensitive ?
Yes, Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
6. What is syntax for Class Name, Method Name and File Name ?
Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example class MyFirstJavaClass
Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example public void myMethodName()
Program File Name - Name of the program file should exactly match the class name.
7. What are Access Modifiers and Non Access Modifiers ?
Access Modifiers: default, public , protected, private
Non-access Modifiers: final, abstract, strictfp
8. What is Java Strictfp Keyword ?
Java strictfp keyword ensures that you will get the same result on every platform if you perform operations in the floating-point variable. The precision may differ from platform to platform that is why java programming language have provided the strictfp keyword, so that you get same result on every platform. So, now you have better control over the floating-point arithmetic. Strictfp legal on Class, Interface and methods Only not allowed for constructor or identifier declaration.
9. What are type of variables in Java?
Local Variables
Class Variables (Static Variables)
Instance Variables (Non-static variables)
Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.
Instance variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.
Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.
Instance variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.
Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.
10. What are Enums ?
Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.With the use of enums it is possible to reduce the number of bugs in your code.
11. Give an example where we can use Enums ?
if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium and large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.
12. Explain OO concepts ?
fundamental concepts:
- Polymorphism
- Inheritance
- Encapsulation
- Abstraction
- Classes
- Objects
- Instance
- Method
- Message Parsing
13. What is Singleton Class ?
Singleton Class is where you would be able to create only one instance of a class. The Singleton's purpose is to control object creation, limiting the number of obejcts to one only. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources such as database connections or sockets.
14. Why multiple inheritance is not supported in java?
To reduce the complexity and simplify the language, multiple inheritance is not supported in java.
Consider a scenario where A, B and C are three classes. The C class inherits A and B classes. If A and B classes have same method and you call it from child class object, there will be ambiguity to call method of A or B class.
Since compile time errors are better than run-time errors, java renders compile time error if you inherit 2 classes. So whether you have same method or different, there will be compile time error now.
Comments
Post a Comment