Java interview OOP
Access Modifiers
helps to restrict the scope of a class, constructor, variable, method, or data member.
Access control
is a mechanism, an attribute of encapsulation which restricts the access of certain members of a class to specific parts of a program.
Overloading
is an example of compile time polymorphism. Compile Time Polymorphism or Static Polymorphism is resolved during compiler time.
Overriding
is an example of run time polymorphism. Run Time Polymorphism or Dynamic Polymorphism is resolved during run time.
Abstraction
is the methodology of hiding the implementation details from the user and only providing the functionality to them
Inheritance
is the property of an object to acquire all the properties and behavior of its parent object. Represents the IS-A relationship which is also known as a parent-child relationship.
Polymorphism
is the property of an object which allows it to take multiple forms.
Overriding rules
method argument list must match the method. The return type must be the same or subtype of method. Access level cannot be more restrictive than method.
Overloading rules
methods must have different argument list, It can have different return types if argument list is different, It can throw different exceptions, It can have different access modifiers.
get method
returns the variable value of the variable name.
set method
takes a parameter and assigns it to the name variable
Public
Classes, methods, or data members that are declared as public are accessible from everywhere in the program. There is no restriction on the scope of public data members. Visible to the world.
Classes
Blueprint from which an object's properties and behaviors are decided.
Encapsulation
Is the mechanism of wrapping up of data and code acting on the methods together as a single unit. It is achieved by declaring the variables of a class as private and then providing the public setter and getter methods to modify and view the variable values.
Objects
Real world entities that has their own properties and behaviors.
Default
The data members, class or methods which are not declared using any access modifiers. Are accessible only within the same package. Visible to the package. No modifiers are needed.
Private
The methods or data members declared as private are accessible only within the class in which they are declared. Any other class of the same package will not be able to access these members. Visible to the class only.
Protected
The methods or data members declared as protected are accessible within the same package or subclasses in different packages. Visible to the package and all subclasses
Properties
a class that is a child class (subclass) of Hashtable. Used to maintain the list of values in which key and value pairs are represented in the form of strings.
Object Oriented Programming
a methodology or paradigm to design a program using Objects and Classes.
parameter
a value that you can pass to a method in Java