Posts

Comparison Between Inheritance and Polymorphism

  Introduction What is Inheritance? The ability of a class to use the properties and characteristics of another class is called as inheritance. Basically,In inheritance two types of classes are involved Superclass and subclass, Subclass : The class which uses the properties and characteristics of other class is called a subclass. Superclass : The class whose properties and characteristics are used by other classes is called a superclass. extends keyword is used in java for performing inheritance . Syntax :   class BaseClass_Name   {  //methods and fields of BaseClass }                                              class SubClass_Name extends BaseClass_Name {  //Methods and fields of SubClass } Why use inheritance ?          The most important use of inheritance is code reusability, we can reuse the code (methods and fields) written in super class by using base class as well. Method overriding  is also called as a runtime polymorphism

Linked list

Image
  What is linked list? One disadvantage of using array to store data is that array are static structures and therefore cannot be easily extended or reduced to fit the data set. Arrays are also expensive to maintain new insertion and deletion of elements to avoid this we will learn new data structure called Linked List. A linked list is a data structure used for storing collections of data. A linked list has the following properties. ·        Successive elements are connected by pointers ·        The last element points to NULL ·        Can grow or shrink in size during execution of a program ·        Can be made just as long as required ·        Does not waste memory space (but takes some extra memory for pointers). It allocates memory as list grows. Representation of Linked List Let's see how each node of the linked list is represented. Each node in linked list consists of:     A data item.