REVATURE INTERVIEW QUESTIONS AND ANSWERS| LATEST UPDATE 100% SOLVED
What is method overriding? Remember @Override to create your own System.out.println
method, same idea. You use the same method name from a parent class and manipulate it's
use
**
It MUST have same name and parameters as the parent class method
**
Can a static method be overridden? No, because it is bound with class whereas instance
methods are bound with an object
**
Static belongs to the class area, instance belongs to the heap area
**
What is encapsulation? 1) A process of wrapping code and data together into a single unit
(e.g. a capsule containing different medical powders)
**
, We can create an encapsulated class by making all the data members of it private, then use
setter getter methods to get data in it
**
4 advantages of encapsulation 1) By providing getter/setters, you make the class READ-
ONLY / WRITE-ONLY
2) It provides you the control over the data by being able to do 1)
3) It is a way to hide data in Java because other classes will not be able to access the private
data members
4) It is easy to test
4 access modifiers 1) Private
Access within class
2) Default
Access within class, package
What is method overriding? Remember @Override to create your own System.out.println
method, same idea. You use the same method name from a parent class and manipulate it's
use
**
It MUST have same name and parameters as the parent class method
**
Can a static method be overridden? No, because it is bound with class whereas instance
methods are bound with an object
**
Static belongs to the class area, instance belongs to the heap area
**
What is encapsulation? 1) A process of wrapping code and data together into a single unit
(e.g. a capsule containing different medical powders)
**
, We can create an encapsulated class by making all the data members of it private, then use
setter getter methods to get data in it
**
4 advantages of encapsulation 1) By providing getter/setters, you make the class READ-
ONLY / WRITE-ONLY
2) It provides you the control over the data by being able to do 1)
3) It is a way to hide data in Java because other classes will not be able to access the private
data members
4) It is easy to test
4 access modifiers 1) Private
Access within class
2) Default
Access within class, package