aspose file tools*
The moose likes Java in General and the fly likes what is a concrete class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is a concrete class" Watch "what is a concrete class" New topic
Author

what is a concrete class

Gajendra Kangokar
Ranch Hand

Joined: Dec 25, 2012
Posts: 81
    
    1

Hello everybody..
there are interfaces and abstract classes.Now what is this concrete class.
is concrete class anyway related to the interfaces or abstract class.
please can i get to know this with an example.

Thanks a lot..
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7816
    
  21

Gajendra Kangokar wrote:Now what is this concrete class.

A class that can be instantiated. In general (but not always), this means that you can say:
MyClass m = new MyClass(...);
without getting a compiler error.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Any class, concrete or abstract can be written to implement an interface. You cannot instantiate a class or interface until you have implementations for all its methods.
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

A class is called concrete when it defines all the member and inherited methods and which can be instantiated.

http://plainoldjavaobject.blogspot.in
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Lalit Mehra wrote:A class is called concrete when it defines all the member and inherited methods and which can be instantiated.
Not at all. A class is called concrete when it is not abstract.
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

Campbell Ritchie wrote:Not at all. A class is called concrete when it is not abstract.


Ok. But i think a abstract class cannot be instantiated while a concrete class can be.
A concrete class also gives definition to all the inherited methods and the once which are specific to the concrete class.
Isn't it so ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Lalit Mehra wrote:
Campbell Ritchie wrote:Not at all. A class is called concrete when it is not abstract.


Ok. But i think a abstract class cannot be instantiated while a concrete class can be.


You said: "A class is called concrete when it defines all the member and inherited methods and which can be instantiated." The part about "when it defines all the member and inherited methods" is incorrect, or at the very least confusing and unnecessary.

Simply, "A class is called concrete when it is not abstract," exactly as Campbell said, is correct and complete.

A concrete class also gives definition to all the inherited methods and the once which are specific to the concrete class.
Isn't it so ?


I don't know what, if anything, the language spec says about whether a class "defines" methods that it simply inherits from its parents and overrides. Maybe it does, maybe it doesn't, but I can't be bother to look it up. Since it adds nothing to the definition even if it is correct, there's no point.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Lalit Mehra wrote: . . . Ok. But i think a abstract class cannot be instantiated while a concrete class can be.
You can create an anonymous class from an abstract class and instantiate it like that. That is not strictly instantiating the abstract class however.
A concrete class also gives definition to all the inherited methods and the once which are specific to the concrete class.
Isn't it so ?
You can have abstract classes with all methods implemented.

As I said yesterday, a concrete class is one which is not marked abstract. You can have concrete classes which cannot be instantiated, too. An example is java.lang.Math.
The Java Language Specification appears not to use the phrase “concrete class”.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7816
    
  21

@Gajendra: I hope all this extra discussion isn't confusing you.

The fact is that Campbell is absolutely right, and Lalit and I are wrong (sorry if I misled you with my post): A concrete class is a named class that is not abstract; simple as that.

Winston
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Winston Gutkowski wrote:A concrete class is a named class that is not abstract; simple as that.


Any particular reason for restricting it to named classes? I'm not aware of any official definition, but I would consider anonymous classes to be concrete as well. I've always taken it to mean, simply, "not abstract," as Campbell is saying.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7816
    
  21

Jeff Verdegan wrote:Any particular reason for restricting it to named classes? I'm not aware of any official definition, but I would consider anonymous classes to be concrete as well. I've always taken it to mean, simply, "not abstract," as Campbell is saying.

Yeah, I guess that's the problem. It's one of those terms that crops up a lot, but doesn't seem to have an official definition.

Mine comes from the word "concrete" itself which, even if used metaphorically, means something substantive. To me, an anonymous class is simply an object - it just happens to be defined and instantiated at the same time. It doesn't define a type, and you certainly can't do anything else with it, so to me there's nothing "concrete" about it.

But hey, I quite understand your disagreement.

Winston
Gajendra Kangokar
Ranch Hand

Joined: Dec 25, 2012
Posts: 81
    
    1

Yes Winston,
it is bit clear now that a concrete class is a simple non-abstract class where a reference variable of the same can be created to point a new object.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Gajendra Kangokar wrote:Yes Winston,
it is bit clear now that a concrete class is a simple non-abstract class where a reference variable of the same can be created to point a new object.


You're overcomplicating it. Reference variables have nothing to do with whether a class is concrete.

Once again: A concrete class is simply a non-abstract class. Or, if you prefer Winston's definition, a non-abstract, non-anonymous class. None of that has any relation to reference variables.
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Gajendra ,

An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the methods that are not implemented in the base class. A derived class that implements all the missing functionality is called a concrete class .

Regards,
James
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

James Peterson wrote:Hi Gajendra ,

An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the methods that are not implemented in the base class. A derived class that implements all the missing functionality is called a concrete class .


By that definition, Child1 and Child2 would be concrete classes, since both are derived from an abstract base class and both implement all the missing functionality from that base class.


So your definition is both more complicated and vague than the ones already provided several times, and doesn't really make any sense.
 
jQuery in Action, 2nd edition
 
subject: what is a concrete class