The ability to define a function in multiple forms is called Polymorphism. In java, c++ there are two types of polymorphism: compile time polymorphism (overloading) and run time polymorphism (overriding). Method overriding: Overriding occurs when a class method has the same name and signature as a method in parent class. When you override methods, ...

Read More

Inheritance allows a Child class to inherit properties from its parent class. In Java this is achieved by using extends keyword. Only properties with access modifier public and protected can be accessed in child class. public class Parent { public String parentName; public String familyName; protected void printMyName() { System.o...

Read More

Abstraction is a way of converting real world objects in terms of class. Its a concept of defining an idea in terms of classes or interface. For example creating a class Vehicle and injecting properties into it. E.g public class Vehicle { public String colour; public String model; }

Read More

The encapsulation is achieved by combining the methods and attribute into a class. The class acts like a container encapsulating the properties. The users are exposed mainly public methods.The idea behind is to hide how things work and just exposing the requests a user can do.

Read More

Association is a relationship where all object have their own life cycle and there is no owner. Let's take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own life cycle. Both can create an...

Read More

Aggregation is a specialize form of Association where all object have their own life cycle but there is ownership and child object can not belongs to another parent object. Let's take an example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy. We ca...

Read More

Composition is again specialize form of Aggregation and we can call this as a "death" relationship. It is a strong type of Aggregation. Child object does not have their life cycle and if parent object deletes all child object will also be deleted. Let's take again an example of relationship between house and rooms. House can contain multiple rooms ...

Read More

The different OOP concepts are: Polymorphism Inheritance Abstraction Encapsulation Aggregation Composition Association

Read More

final - A final variable acts as a constant, a final class is immutable and a final method cannot be overridden while doing inheritance. finally - The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other s...

Read More

== operator is used to compare the references of the objects. public boolean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. But since the method can be overridden like for String class. equals() method can be used to compare the values of two objects.  String str1...

Read More

The non-final methods in Object class are equals(), hashCode(), toString(), clone() and finalize(). The other methods like wait(), notify(), notifyAll(), getClass() are final methods and therefore cannot be overridden. Let us look at 2 main non-final methods, which are meant primarily for extension. The equals() and hashCode() methods prove to be v...

Read More

The toString() method provided by the java.lang.Object returns a string, which consists of the class name followed by an [email protected] sign and then unsigned hexadecimal representation of the hashcode, for example [email protected]. This hexadecimal representation is not what the users of your class want to see. Providing your toString() method...

Read More

  Modifier Usage Description public Outer classes, interfaces, constructors, Inner classes, methods and field variables. A class or interface may be accessed from outside the package. Constructors, inner classes, methods and field variables may be accessed wherever their class is accessed. protected Constructors, inner classes, methods, and field v...

Read More

 A final class can’t be extended i.e. A final class can not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (i.e. it is a constant).  

Read More

Bertrand Meyer formalized a programming methodology called Design by Contract, which has become popular in some groups. In addition to specifying programming code to carry out the operations of a function (method), the programmer also specifies: Preconditions - assumptions the function makes. These are usually expressed as statements that must be t...

Read More

Association is a relationship between two objects. In other words, association defines the multiplicity between objects. You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects. Aggregation is a special form of association and Composition is a special form of aggregation. Example:...

Read More

Method Overloading Overloading deals with multiple methods in the same class with the same name but different method signatures. class OverloadingClass { public void sum(int x, int y) {   ...   }     public void sum(int x, int y, int z) {   ...   } } Both the above methods have the same method names...

Read More

Static Keyword When we need class member which is independent on object and directly related to class we declare that type of members using static keyword. Only one time memory will be allocated to static variable so if it is accessed by different object, value will be same for all. In java we can have static block, variable, methods and inner clas...

Read More

Overloading Methods In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java supports p...

Read More

Anonymous classes make your code more concise. They enable you to declare and instantiate a class at the same time, often single-use classes for convenience. They are like local classes except that they do not have a name. The following example instantiates a new ActionListener to handle events associated with a button: button.addActionListener(n...

Read More

FOLLOW US ON LinkedIn



Explore Tutu'rself