This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to call abstract class  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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 IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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();
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!