Java Interview Questions - Method
1. What are the different types of methods in java?
There are 6 types of method support by java. They are:
2. What is static and non-static method in java?
If the method declares with Static modifier it should declare as static method. If the method declare without any Static modifier known as non-static method.
3. What are the uses of final keyword in java?
Final keyword can be used in 3 different place all over in java:
4. What is native method and why to use it?
If the method declare with native modifier ten it is known as native modifier. And This method is use to communicate from java application to other environment like C & C++.
5. What is abstraction in java and types of abstraction?
Abstraction is the concept of representing the essential feature without including the background details & explanation.
6. What are the uses of abstract keyword in java?
Abstract is a keyword in java which supports the concept of abstraction.
7. What is interface?
It is a description of a set of method that conforming implementing classes must have.
8. What is similarity between abstract class and interface?
The similarity between abstract class and interface is object cannot create in both the classes.
9. What are the difference between abstract class and interface?
The difference between both is.
- Interface supports 100% abstraction WHERE abstract class support 0- 100% abstraction.
- AllmethodofInterfaceareimplicitlypublic&abstractWHEREusercan declare any type of method in abstract class.
- The nature of variable in case of interface is public, static &final WHERE user can declare any kind of variable in case of abstract class.
- Interface support the concept of Multiple inheritance WHERE Abstract class never support it.
- Constructor cannot design in interface but it possible in case of abstract class.
10. What is the procedure to call a non - static and static method in java?
Static method can be called directly with in the same class and it can be called by class name or object name with in the same or different class. Non static method can be called by the object only.
11. When Abstract methods are used?
When class not able to instantiate and able to contains complete as well as abstract method.
12. If a method is declared as protected, where may the method be accessed?
If the method declare as protected it may accessed with in inside the same class, in same package/folder, and outside the package/folder (if inherited).
13. What is the impact of declaring a method as final?
If the method declares with Final it cannot override.
14. Can we have two methods in a class with the same name?
Yes name of two method may be same within a single class, it is the concept of overloading.
15. How can we pass argument to a function by reference instead of pass by value?
By Object passing.
16. Which methods have no body?
Abstract methods have no body.
17. What is the use of Interface keyword?
Interface keyword used to define user define interface in java.
18. State the nature of variable in case of interface?
The nature of variable in case of interface is Public, Static and Final.
19. Is abstract class supports multiple inheritance and why?
Abstract class never supports multiple inheritance. Because it creates ambiguity of members.
20. Can abstract class be instantiated ?
No abstract class cannot be instantiated.
21. Is it possible to design a constructor within abstract class?
Yes, it is possible to design constructor in abstract class.
22. When the constructor within the abstract class invoked?
Not possible within that abstract class, but the constructor of abstract class automatically invoked when programmer creates the object of sub class.
23. Which method use to communicate from java to other environment?
Native method is used to communicate from java to other environment.
24. Which method indicate compiler not to check existence of method at compilation?
Native method indicate compiler not to check existence of method at compilation.
25. Define LoadLibrary() method?
It is a predefined static method present in System class which uses to load the library passed as an argument.