Shay

Shay

  • NA
  • 5
  • 0

Basic question

Jan 13 2009 1:12 PM

Hi,

I have a question regarding the inner workings of the abstract classes and inheritance:

I know that value-type are kept in the stack and refeence-type are kept in the heap.

Take the following code for example:

abstact class figure{

double dim1,dim2;

  Figure(double a, double b){

  dim1 = a;

  dim2 = b;

}

abstarct double area();

}//End Abstract class figure

class Rectangle : Figure

{

   Rectangle(double a,double b): base(a,b){}

double area()

{

    return dim1*dim2

}

}//End class Rectangle

 public static void main(String args[])

{

    Rectangle r = new Rectangle(9,5);

    Figure figref;

    figref = r;

    ....More code here

}

My question is: I know that r is stored in the stack and it is pointing on a Rectancle that is stored in the heap. What is the case for figref (since it is not been instantiated).  An abstract class is stored in the heap the same as all other classes? Is there some kind of a pointer between a baseClass and a derivedClass? 

 

Thanks

Shay


Answers (5)