Monday, 4 June 2012

Monday (June 4' 2012)

A whole new week starts. Got up at 6 a.m, was at the bus stand by 7a.m. and finally reached Chandigarh at about 9:30 a.m. Today, we were taught about the concepts of Vectors, String Buffer, Inheritance and use of Super keyword  in case of Java. Vector class can be used to create a generic dynamic array known as vector that can hold objects of any type and any number. While String creates strings of fixed length, String Buffer created strings of flexible length. Inheritance in Java has same concept as Inheritance in C++ , though Java do not support multiple and hybrid types of Inheritance.


Example:-

1. Java code showing use of Super keyword and also involving concept of Inheritance.


import java.util.*;
public class abc {
    int a,b;
    abc(int x,int y)
    {
        a=x;
        b=y;
    }
    void show()
    {
        System.out.println("A="+a);
        System.out.println("B="+b);
    }
}
    class Area extends abc
    {
        Area()
        {
            super(4,6);
        }
            void calarea()
            {
                int ar=a*b;
                System.out.println("Area="+ar);
            }
    }
class Alpha
{
    public static void main(String [] args)
    {
        Area obj=new Area();
        obj.show();
        obj.calarea();
    }
}



OUTPUT:-

   A=4
   B=6
   Area=24