
An interface can't have behavior or state.Īn abstract class is a class that cannot be instantiated, but has all the properties of a class including constructors. Java provides interfaces and abstract classes for describing abstract types.Īn interface is a contract or specification without any implementation. In plain English, abstract is a concept or idea not associated with any specific instance and does not have a concrete existence.Ībstraction in Object Oriented Programming refers to the ability to make a class abstract.Ībstraction captures only those details about an object that are relevant to the current perspective, so that the programmer can focus on a few concepts at a time. Overriding may be also called runtime polymorphism. In case of variables (static and non-static) and static methods, when you invoke a method using a reference type variable, the method or variable that belong to the reference type is invoked.

Overriding is not applicable for static methods or variables (static and non-static). Here, the actual method called will depend on the object at runtime, not the reference type.

Parent p = new Child()) and invoke a method, the overriden child class method will be invoked. When you refer to a child class object using a Parent reference (e.g.

We can override an instance method of parent class in the child class. Overloading may be also called compile time polymorphism. The "+" operator can be used for addition as well as string concatenation. Java doesn't allow operator overloading except that "+" is overloaded for class String. The same method name (method overloading) or operator symbol (operator overloading) can be used in different contexts. Java supports different kinds of polymorphism like oveloading and overriding. The ability to change form is known as polymorphism. Java supports multiple inheritance (multiple parents, single child) only through interfaces. This is done to avoid some confusions and errors such as diamond problem of inheritance. Java supports single-parent, multiple-children inheritance and multilevel inheritence (Grandparent-> Parent -> Child) for classes and interfces. Car is known as derived class, Child class or subclass. In the above example, Vehicle parent class is known as base class or superclass. Vehicle class will have properties and functionalities common for all vehicles. Car will inherit those common properties from the Vehicle class and then add properties which are specific to a car. Inheritance describes the parent child relationship between two classes.Ī class can get some of its characteristics from a parent class and then add more unique features of its own. For example, consider a Vehicle parent class and a child class Car. Static variables and methods are not purely object oriented because they are not specific to instances (objects) but common to all instances.Įncapsulation is the process of wrapping up of data (properties) and behavior (methods) of an object into a single unit and the unit here is a Class (or interface).Įncapsulate in plain English means to enclose or be enclosed in or as if in a capsule. In Java, everything is enclosed within a class or interface, unlike languages such as C and C++ where we can have global variables outside classes.Įncapsulation enables data hiding, hiding irrelevant information from the users of a class and exposing only the relevant details required by the user. We can expose our operations hiding the details of what is needed to perform that operation. An object is a particular instance of a class which has actual existence and there can be many objects (or instances) for a class.
#JAVA OOPS CONCEPTS WIKI SOFTWARE#
If you are new to object oriented approach for software development, you can first read about object oriented approach in little more detail object-oriented-systems-development.Īn object in OOP has some state and behavior. In Java, the state is the set of values of an object's variables at any particular time and the behaviour of an object is implemented as methods.Ĭlass can be considered as the blueprint or a template for an object and describes the properties and behavior of that object, but without any actual existence. These features are generally referred to as the OOPS concepts.

Object-Oriented Programming (OOP) consist of some important concepts namely Encapsulation, Polymorphism, Inheritance and Abstraction. Object-Oriented Programming (OOP) uses "objects" to model realworld objects.
