Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java abstract class

 
Ranch Hand
Posts: 72
MySQL Database AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
abstract class poly
{
public int l,b;
poly(int x,int y)
{
l=x;
b=y;
}
void disp()
{
System.out.print("inside poly");
}
abstract void area();
}
class rect extends poly
{
rect(int x,int y)
{
super(x,y);
}
void area()
{
System.out.println(l*b);
}

@Override
void disp()
{
System.out.println("I am rectangle");
}
}
public class refconcept
{
public static void main(String args[])
{
poly ref;
rect r=new rect(10,10);
poly refer=new rect(10,5);
if(r instanceof poly)
{
ref=r;
ref.area();
ref.disp();
refer.area();
refer.disp();

}
}
}



Output:
100
I am rectangle
50
I am rectangle


I am anyhow can't call method disp() in parent class even super keyword not working.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
https://coderanch.com/how-to/java/UseOneThreadPerQuestion

https://coderanch.com/how-to/java/UseCodeTags
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please continue in the previous thread here. I am locking this thread.

Can you please post your query as a reply to this post.
 
    Bookmark Topic Watch Topic
  • New Topic