Question-11. What is static method ?
Answer- A static method belongs to the class rather than object of a class.
A static method can be invoked without the need for creating an instance of a class.
static method can access static data member and can change the value of it.
Question-12. Why main method is static ?
Answer- because object is not required to call static method if It were non-static method,jvm creats object first then call main() method that will lead to the problem of extra memory allocation.
Question-13. What is static block ?
Answer- Is used to initialize the static data member.
It is executed before main method at the time of classloading.
Question-14. Can we execute a program without main() method ?
Answer- Yes, one of the way is static block.
Question-15. What if the static modifier is removed from the signature of the main method ?
Answer- Program compiles. But at runtime throws an error “NoSuchMethodError”.
Question-16. What is this in java ?
Answer- It is a keyword that that refers to the current object.
Question-17. What is Inheritance ?
Answer- Inheritance is a mechanism in which one object acquires all the properties and behavior of another object of another class. It represents IS-A relationship. It is used for Code Re-usability and Method Overriding.
Question-18. Which class is the superclass for every class ?
Answer- Object class.
Question-19. Why multiple inheritance is not supported in java ?
Answer- To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class.
Question-20. What is composition ?
Answer- Holding the reference of the other class within some other class is known as composition.