5 Replies Latest reply: Sep 18, 2006 11:27 AM by 3004 RSS

    subclass Vs Concrete class

    807598
      Hi,

      What is the exact difference between subclass and concrete class?

      What is the need in subclassing abstract class to again abstract class?


      Thanks in Advance,
      venu.
        • 1. Re: subclass Vs Concrete class
          3004
          Hi,

          What is the exact difference between subclass
          and concrete class?
          "Subclass" defines a class' relationship to another class.
          class A extends B
          B is a subclas of A.

          Every class in Java except Object is a subclass of some other class.

          A concrete class is one that is not abstract.
          class A {}
          abstract class B{}
          Cass A is concrete. Class B is not.

          A class can be both a subclass and concrete. In fact, every single concrete class except Object is a subclass.


          What is the need in subclassing abstract class to
          again abstract class?
          You would do that when you're able to provide concrete implementations for some but not all of the abstract methods
          • 2. Re: subclass Vs Concrete class
            807598
            Q: What is the exact difference between subclass and concrete class?
            A: Inheritance in java introduces the concept of subclass & superclass. Both the terms cannot be used individually. They can be used only in reference. When our class inherits a another class using extends keyword i.e

            Class X extends Y

            then class X is called the subclass of class Y and
            class Y is called the superclass of class X.

            Any class which is not abstract is called a concrete class.

            thrinath.j
            • 3. Re: subclass Vs Concrete class
              3004
              >
              "Subclass" defines a class' relationship to another
              class.
              class A extends B
              B is a subclas of A.
              Strike that. Reverse it.

              A is a subclass of B.

              Don't know what I was smoking last night.
              • 4. Re: subclass Vs Concrete class
                807598
                Hi,

                U mean to say Concrete classes are instantiatable and every concrete class is a subclass of some super class.Plz clarify me if i am wrong.

                cheers,
                venu.
                • 5. Re: subclass Vs Concrete class
                  3004
                  Hi,

                  U mean to say Concrete classes are instantiatable
                  and every concrete class is a subclass of some
                  super class.Plz clarify me if i am wrong.
                  That's correct. But it's also true that every class--both concrete and abstract--is a subclass of some superclass, except Object which has no superclass.




                  NOTE: The following is simply provided in the interest of completeness because I'm a ballsniffing pedant. It's not that important to what you're asking about, and may just cause more confusion. Feel free to ignore it.

                  Also, it's possible to make a concrete class non-instantiable by having a single private constructor and throwing an exception from it, but that's a runtime issue--the compiler will let you insstantiate the class (only from within itself if the c'tor is private).