dcsimg
What is the benifit of inheritence and instancing a object in another class.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   badrinath_punchagnula
Posted On:   Sunday, September 29, 2002 10:05 PM

hi this doubt keeps on worring me when i start writing programmes in java. why java has instance and inheritence? For example class Rest { private int i = 100; public void method() { System.out.println(i); } } class Test { public void methodTest() { System.out.println(i); } public static void mian(String []args) { Rest r = new Rest(); Test t = new Test(); t.methodTest(); r.method() } } Now my question is i can inherit the class Rest into Test and i can access the methods in the Rest class. what is the differen if we   More>>

hi
this doubt keeps on worring me when i start writing programmes in java.

why java has instance and inheritence?

For example

class Rest
{
private int i = 100;
public void method()
{
System.out.println(i);
}
}

class Test
{
public void methodTest()
{
System.out.println(i);
}

public static void mian(String []args)
{
Rest r = new Rest();
Test t = new Test();
t.methodTest();
r.method()
}
}

Now my question is i can inherit the class Rest into
Test and i can access the methods in the Rest class.
what is the differen if we create instance of the
class and inherit the class to access the base class
methods or properties

It will very helpfull to me if you explain about this
concept.

Thanks in advance

   <<Less

Re: What is the benifit of inheritence and instancing a object in another class.

Posted By:   Sunit_Bhargava  
Posted On:   Sunday, September 29, 2002 11:23 PM

Hi,

so far i think that there is no such benifit of using inheritance or Instancing. but thing is when ur class heavily used methods of base class ,so there u must use Inheritance or simply its a meachanism for defining a new class in terms of a existing class, and when u required one specific method to be called use instancing. one more thing like when u required to call methods from diffrent classes, u can do it only thru instancing. i think this may give answer to ur question. thanks
About | Sitemap | Contact