• Post Reply 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

How to call abstract class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
this is my coding .i have one abstract class that is exrended by class b..
i am creating obj reference for class a...
how will u call the abstract class method amethod() from class a..
the output should be 'b method 1';;
any one know?
Thanks
Ramesh.N


abstract class b{
private int i=1;
public void amethod(){
System.out.println("b method"+i);
}
}

public class a extends b{
private int i=2;
public void amethod(){
System.out.println("a method"+i);
}
public static void main(String arg[]){
b bobj=new a();
bobj.amethod();
}
}
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
General intent of abstract class is to provide implementation for method which requires no overriding.
So what is the intent of overriding abstract method which is implemented?
If you still desperate to call the abstract class method, then remove or change the method name in class b. Then you will be able to call abstract class method.
[ April 07, 2006: Message edited by: Arun Boraiah ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have one abstract class that is exrended by class b..

When I look at your code, it's the other way around - you have a class "a" that extends class "b". You don't have a class that is "extended by class b".

how will u call the abstract class method amethod() from class a..
the output should be 'b method 1';;


Add the following line to the implementation of amethod() in class a:

super.amethod();
 
What's that smell? Hey, sniff this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic