OOPs stands for Object Oriented Programming Structure. It is a method of implementation in which programs are organized as a collection of objects, classes, and methods.
OOPs principles are:
ClassName refName = new ClassName(); Here:
Notes:
Encapsulation is the process of binding data and code together into a single entity.
Inheritance is the process of accessing one class's properties and methods in another class using the extends keyword. The main purpose of using inheritance is code reusability, and it also helps in reducing memory usage by avoiding the creation of duplicate objects or code.
extends keyword.Poly means many, Morphism means forms. Taking more than one form is called polymorphism, or completing one task in many ways. It has 2 types:
When the method name is the same within the same class but the arguments are different, it is called method overloading. Arguments can differ by data type, number of parameters, or the order of parameters.
If we are not satisfied with the parent class logic, we can extend the parent class into a child class and override the same method with the same method name and same arguments — this is called method overriding.
Hiding the implementation part is called abstraction. It has 2 types:
public abstract keyword is mandatory to define an abstract method.extends keyword to access the methods of an abstract class in a subclass.public and abstract are optional.implements keyword to implement the interface methods in a class.No. An abstract method needs to be overridden in a subclass, but a static method cannot be overridden. These two concepts conflict, so Java doesn’t allow abstract static methods.
Yes, we can declare static variables and methods in an abstract class.
Yes, we can overload the methods by just applying the static keyword to them.
Yes, we can declare the main method as: public static final void main(String[] args) {}
No, we cannot declare an interface as final because the interface must be implemented by some class to provide its definition. If you try to do so, the compiler will show an error.
No, because we need to override the abstract method to provide its implementation, whereas we cannot override a final method.
Yes, overloaded methods can also be overridden, but overloading and overriding are separate concepts:
So, you can override a method that is also overloaded.
No, Java is not fully object-oriented because it uses primitive data types like int, char, etc., along with static methods and operators. It supports OOP features but also mixes in procedural concepts.
No, static methods cannot be overridden in Java.
Signup