• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

abstract class

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone tell me why abstract class can't produce instance object?
Thanks.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are not intended to be directly instantiated, only inherited. When a class extends an abstract class, it agrees to provide all of the necessary implementation for the abstract class. If a class can be thought of as a blueprint, and an interface is a contract, then an abstract class is sorta like an unfinished blueprint, with a contract stating what needs to be done to finish the blueprint. Because a subclass will pass the IS-A test for an abstract class, it allows other code to refer to the abstract class, while the actual implementation may very from subclass to subclass. So, I always know that a subclass of abstract class X has a method called Y. I just don't know what Y does, but I can still reference the method and call it.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree but remember, any method that you declare as abstract implies that the class must also be abstract. If you do not declare the class as abstract does the jvm "make" the class abstract if you declare a method abstract and not the class, or does it just throw the error and leave it at that?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a class is not abstract and you declare a method as abstract, it won't compile.

from the compiler:

C:\a\Test.java:1: Test is not abstract and does not override abstract method abstractMethod() in Test
public class Test {
^
1 error

Tony
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic