Why Abstract class is abstract?

praveen murali

Greenhorn

Posts: 8

posted 5 years ago

I have been reading a lot about abstract classes and wonder why actually it is Abstract? Now I do know that, what abstract is and what it means in terms of programming. What I am looking for is -
1) How does an abstract class behave in JVM environment ?
2) Someone told me that footprint of these classes on system memory is null, is it right ?
3) Does the abstract class exist on the java heap, irrespective of the fact that it has been re used or not?

I tried looking for these answers on the net, but nothing has come up yet, if you have a link to guide, thanks much .

praveen murali wrote:I have been reading a lot about abstract classes and wonder why actually it is Abstract? Now I do know that, what abstract is and what it means in terms of programming. What I am looking for is -
1) How does an abstract class behave in JVM environment ?

Just like any other class. I don't understand the question.

2) Someone told me that footprint of these classes on system memory is null, is it right ?

Erm ... see 1.

3) Does the abstract class exist on the java heap, irrespective of the fact that it has been re used or not?

If you mean an instance of an abstract class, then it doesn't exist at all. Abstract classes need to be extended before they can be used.

I tried looking for these answers on the net, but nothing has come up yet, if you have a link to guide,

"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here

Mahesh Kedari

Ranch Hand

Posts: 111

posted 5 years ago

Im not sure what exactly is making you get confused so much.
I will give you one general example. Please note that this is just an example and may not be a real time scenario.

Lets assume, that company A makes a car body, engine, front glass, mirrors and almost everything expect wheels. There is another company B which makes wheels but doesn't actually make the entire car.
Now Company A cannot directly release a car in market right? but Company B can buy a car structure without wheels from company A and attach wheel to it and release a car in market.

Same thing happens with Java. Company B can place a Car Object into memory but company A cannot. But company A can refer a car object created by company B because it knows everything about that car except wheels.

Now hope this explanation clears your doubt about abstraction.

Regards,
Mahesh Kedari - Fidus Technologies Ltd.

praveen murali

Greenhorn

Posts: 8

posted 5 years ago

I am so sorry, that my too many questions got you off guard. I am aware what abstraction is in java and thanks to Mahesh, its more clear now. All I was looking for was the impact an abstract class has on memory, after being instantiated, like do we really go back to the abstract class and load it into memory, from your replies, it seems not . So I guess I will go with that for now.

praveen murali wrote:All I was looking for was the impact an abstract class has on memory, after being instantiated, like do we really go back to the abstract class and load it into memory...

These sorts of questions are rarely of much use in Java. It isn't C or C++ where classes have a predictable memory footprint and format; and in 11 years of using Java I've never had to think about what a class looks like in memory or where it gets loaded. The JVM loads it, I use it; simple as that. When I'm done with it, it collects it whenever it feels like it.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here

praveen murali

Greenhorn

Posts: 8

posted 5 years ago

thanks Winston

Campbell Ritchie

Marshal

Posts: 56546

172

posted 5 years ago

Are you sure you know about abstraction? It has hardly anything to do with abstract classes.

BalaMurali dhar

Ranch Hand

Posts: 60

posted 5 years ago

Abstract class : abstract class is a class that contains one or more abstract method. Abstract method means that is being declared but contains no implementation.
Note : 1) If even a single method is abstract, the whole class must be declared abstract
2) Abstract class may not be instantiated, and require subclasses to provide implementations for the abstract methods.
3) You cannot mark a class as both abstract and final

BalaMurali dhar wrote:Abstract class : abstract class is a class that contains one or more abstract method...

Actually, you're wrong there. An abstract class is a class with the wordabstract in its definition; it doesn't have to have abstract methods (although more often than not it will).

Everything else you said is fine.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here

Mahesh Kedari

Ranch Hand

Posts: 111

posted 5 years ago

1

Agree with Winston.
Having abstract method is not mandatory for an abstract class. Basically the purpose of abstract class is to indicate that you should (not must, when there is no abstract method) customize the behavior of this class before using it.
Abstract class gives you a template with some default behavior.

Regards,
Mahesh Kedari - Fidus Technologies Ltd.

praveen murali

Greenhorn

Posts: 8

posted 5 years ago

Campbell Ritchie wrote:Are you sure you know about abstraction? It has hardly anything to do with abstract classes.

yes, though I was looking for in terms of Abstract classes in Java, not Abstraction in general.