Friday 23 November 2012

ABSTRACT CLASSES

An summary category features zero (or) more no of summary techniques are well as zero (or) more no of tangible technique. we can announce with the summary keyword and key phrase.
Abstract keyword and key phrase is used only for sessions and techniques but not for variables
ABSTRACT METHOD AND ABSTRACT CLASS:
           An summary category contain any body system. It contains only the technique headlines So we can say it is an imperfect technique. An summary category is a category that usually contains some summary techniques.
        Since summary category contains in defective techniques it is not possible to calculate the finish storage  needed to create the item so JVM can not create item mind an summary to an summary category. We should create sub sessions and all item all the summary techniques should be applied (body should be published ) in the sub sessions then it is possible to create item to the sub trainings since they are finish sessions.
  Note:- it is not possible to create the things for summary sessions but it is possible to create referrals factors.

IMPORTANT INTERVIEW QUESTIONS

Q.What is summary class?
ANS:                                    
 An summary category is a category is a technique without technique body system. An summary technique determine this technique does not have a any body system within it sub1, sub2 and sub3 are the three sub sessions where the summary technique is applied as per need of the things. Since the same summary technique is applied in a different way for different things they is capable of doing unique projects.

PROGRAM 1:
    let us create a system where the summary category Myclass has one summary technique which has got various implementations in sub sessions.

//All the item need different execution of the same technique
abstract category Myclass
{
     //this is summary technique
      summary gap determine (double x)
         {
             Program.out.println("square="+(x*x));
          }
}
class sub2 expands My category
{
        //calculate rectangle primary value
         gap calculate(double x)
            {
                system.out.println("square root="+ mathematical.sqrt(x));
             }
}
class sub 3 expands Myclass
{
       //calculate dice value
       gap determine (double x)
       {
                 system.out.println("cube= "+ (x*x*x));
        }
}
class different
{
 community fixed gap main(string args[])
{
   //create sub category object
   sub1 obj1 = new sub1();
   sub2 obj2 = new sub2();
   sub3 obj3 = new sub3();

  //let the things contact and use calculate() method
  obj1.calculate(3);   //calculate square
  obj2.calculate(4);   //calculate rectangle root
  obj3.calcualte(5);   //calculate dice value
  }
}

OUTPUT:
C:\>javac Differnt.java
C:\>java Different]
Square= 9.0
Square primary = 2.0
Cube = 125.0
we cannot create an item summary category but we can create a referrals varying to it as this varying will not take any storage once referrals is create it can be used to consult the things of sub sessions as proven here:

            Myclass ref;   //ref is the referrals of MyclassABSTRACT CLASSES
            ref = obj1;    //ref is referrals to obj1
            ref.calculate(3);    //call obj1's determine () method
           ref = obj2;      //now ref is discussing obj2
           ref.calculate(4);     //call obj2's  determine () method
           ref = obj3;      //now ref is discussing obj3
           ref.calculate(5);     //call obj3s  determine () method

No comments:

Post a Comment