Category Archives: java

Abstract keyword

Abstract Class : Must be Extended Abstract Method : Must be Overridden an abstract method has no body. We can’t have an abstract method in a non abstract class Abstract class can have both abstract and non abstract method We … Continue reading

Posted in java | Tagged | Leave a comment

Method Overloading v/s Method Overridinng

Overriding : Same return type and no of arguments of method The argument list should be exactly the same as that of the overridden method. The return type should be the same or a subtype of the return type declared … Continue reading

Posted in java | Leave a comment

Inheritance v/s Composition

IS -A : House is a BuildingHAS-A : House has a Room. Inheritance : Uni-Directional Composition : Using instance variable that refer to other objects.

Posted in java | Leave a comment

JAVA keywords

Protected :  Only to classes in same package or sub classes of that class. Abstract : Used to declare a class that can’t be instantiated or a method must be implemented by a non abstract modifier. Extends : for inheritance … Continue reading

Posted in java | Leave a comment

Why static method cannot access non static variables

public class StaticTest {     private int count=0;    public static void main(String args[]) throws IOException {        count++; //compiler error: non-static variable count cannot be referenced from a static context    } } Static variable in Java … Continue reading

Posted in java | Leave a comment

All about final, finally and finalizer

final is a keyword used as an modifier for variable,class and method. final variable : Value of variable can not be modified. final method : Method cannot be overridden final class : Class cannot be extended. finally finalizer

Posted in java | Leave a comment

Numbers and Statics

Background : Math class round method does the same thing it rounds the floating number to nearest integer. Only variance is an parameter of round method. So creating a 10 k instance of Math Class seems like a waste of … Continue reading

Posted in java | Leave a comment