Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract classes - instantiation

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I read somewhere


A class that is abstract may not be instantiated (ie, you may not call its constructor)


Can someone please elaborate on this ?

This code works --

 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More to the point, please recompile with "javac -Xlint:unchecked" (or better, "javac -Xlint:all") and find out for sure exactly what the compiler disagrees with!
 
Dave Kairys
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has to do with polymorphism. All abstract methods must be implemented(or overridden). In order to override a method, you would need to have code in another method that would do this.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not quite true. You can, and in fact, you must, call a constructor of an abstract class, from a subclass' constructor.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arnb --

You posted a couple of these today, questions that start with "I just read..." My advice to you (if these are all coming from the same source) is that you don't read this particular book, tutorial, or study guide any further. Wherever these quotes are coming from, you're getting a lot of bad information.
 
Dave Kairys
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
What did you mean by
It's not quite true.

I am new to Java and I was referencing the Head First Java text when I provided some insight into the proposed question. Please elaborate on your comment.

Thanks!
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

I agree with you. I was actually looking for some certification book which explains or describes as the Java Objectives for SCJP.

Any book in which the chapters or the sections are kind of exact replica of the order in which the Objectives are mentioned in Sun's SCJP requirement ?
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any certification book which follows a similar organisation of the chapters and sections same as that of the SCJP Objective ?
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have heard that Kathy Sierra's book is very good and helpful. Does that follow similar SCJP Objective structure ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic