Category Archives: Basic Oops

Can a private method in super class be overriden in the sub-class?

No, a private method cannot be overridden since it is not visible from any other class. If we do this than its a new method for your subclass that has no relation to the superclass method. One way to look at it is to ask yourself whether it would be legal to write super.func() in Read More →

Is it possible to override static methods in java?

Answer is NO if you think from the perspective of how an overriden method should behave in Java. But, you don’t get any compiler error if you try to override a static method. That means, if you try to override, Java doesn’t stop you doing that but you certainly don’t get the same effect as Read More →

Java – Overriding

If a class inherits a method from its super class, then there is a chance to override the method provided that it is not marked final. The benefit of overriding is: ability to define a behavior that’s specific to the subclass type which means a subclass can implement a parent class method based on its Read More →

Difference between an interface and an abstract class?

We have seen in previous posts what is abstract class and interface. Here we will compare and see difference between these two. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Interface is a Java Object containing method declaration and doesn’t contain implementation. The Read More →

final keyword in java

The final keyword in java is used to restrict the user. The final keyword can be used in many context. Final can be: 1. Vriable 2. Method 3. Class If you make any variable as final, you cannot change the value of final variable(It will be constant). There is a final variable speedlimit, we are Read More →

Why doesn’t the Java language support multiple inheritance?

There are 2 reasons mentioned that will give you a idea why we don’t have multiple inheritance in java. 1st is ambiguity around Diamond problem, consider a class A has foo() method and then B and C derived from A and has there own foo() implementation and now class D derive from B and C Read More →

Difference between static and final method in java

Static methods can be overriden, but they cannot be overriden to be non-static,Whereas final methods cannot be overridden. A static method is a method that’s invoked through a class, rather than a specific object of that class. Static methods can only access static variables – they can’t use anything that’s specific to a particular object. Read More →

Abstract class

Before abstraction let’s first understand the abstraction. Abstraction Abstraction is the process of hiding the implementation details and showing only functionality to the user. It hides the internal details. Ways to achieve abstraction: 1. Interface 2. Abstract class Abstract class A class that is declared as abstract is known as an abstract class. It needs Read More →

Interface in java

What is an Interface? An interface is a description of a set of methods that conforming implementing classes must have. An interface may never contain method definitions. One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java must have exactly one base class. A Java class may implement, and an Read More →

what are the differences between final, finally, finalize in java?

final: final is a keyword. The keyword “final” in Java is used in different ways depending on the context. We can have final methods, final classes, final data members and final local variables. A final class implicitly has all the methods as final, but not necessarily the data members. A final class may not be Read More →