• 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

Abstract class

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In an abstract class i can have non-abstract methods.



How do i access this print function in the class that extends the abstract class a?

Thank you,

Christoffer
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just call it like any other method that belongs to the subclass.

(Assuming it's accessible. You haven't specified an access modifier, so it's only visible within the same package. But then so is the class itself, so any subclasses must be in the same package anyway).
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christoffer Blyerts wrote:Hi,

In an abstract class i can have non-abstract methods.



How do i access this print function in the class that extends the abstract class a?

Thank you,

Christoffer



You cannot instantiate an abstract class i.e you cannot do like this for e.g a obj = new a(); that would result in compiler error. now when a concrete class extends this abstract class then it inherits all the function defined in abstract class(since it is a concrete implementation you need to define method which you have marked abstract). now you can simply create object of your subclass and call the method as you normally do. and ya don't forget about the thing about access modifiers that Matthew mentioned in his post.

as a note try to follow Sun java naming conventions in your code. class name should follow CamelCasing. you shouldn't declare it a, b or helloworld. Use camelcasing and use words which are nouns.
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic