Sie sind auf Seite 1von 4

Question related to Method

1. What are the different types of methods in java?

Ans:
There are 6 types of method support by java .They are
i. Static Method
ii. Non Static Method
iii. Final Method
iv. Abstract Method
v. Native Method
vi. Synchronized Method.

2. What is static and non-static method in java?

Ans:
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?

Ans:
Final keyword can be used in 3 different place all over in java
i. If the Variable is final it cannot be modified.
ii. If the method is final cannot override.
iii. If the class is final it cannot be override.

4. What is native method and why to use it?

Ans:
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?

Ans:
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?

Ans:
Abstract is a keyword in java which supports the concept of abstraction.

7. What is interface?

Ans:
It is a description of a set of method that conforming implementing classes must
have.

8. What is similarity between abstract class and interface?


Ans:
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?

Ans:
The difference between both is
i. Interface supports 100% abstraction WHERE abstract class support 0-
100% abstraction.
ii. All method of Interface are implicitly public & abstract WHERE user can
declare any type of method in abstract class.
iii. 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.
iv. Interface support the concept of Multiple inheritance WHERE Abstract
class never support it.
v. 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?

Ans:
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?

Ans:
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?

Ans:
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?

Ans:
If the method declares with Final it cannot override.

14. Can we have two methods in a class with the same name?

Ans:
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?

Ans:
By Object passing
16. Which methods have no body?

Ans:
Abstract methods have no body.

17. What is the use of Interface keyword?

An:
Interface keyword used to define user define interface in java.

18. State the nature of variable in case of interface?

Ans:
The nature of variable in case of interface is Public, Static and Final.

19. Is abstract class supports multiple inheritance and why?

Ans:
Abstract class never supports multiple inheritance. Because it creates ambiguity
of members.

20. Can abstract class be instantiated ?

Ans:
No abstract class cannot be instantiated.

21. Is it possible to design a constructor within abstract class?

Ans:
Yes, it is possible to design constructor in abstract class.

22. When the constructor within the abstract class invoked?

Ans:
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?

Ans:
Native method is used to communicate from java to other environment.

24. Which method indicate compiler not to check existence of method at compilation?

Ans:
Native method indicate compiler not to check existence of method at compilation.

25. Define LoadLibrary() method ?


Ans:
It is a predefined static method present in System class which uses to load the
library passed as an argument.

Das könnte Ihnen auch gefallen