File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Help Me - Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help Me - Inheritance" Watch "Help Me - Inheritance" New topic

Help Me - Inheritance

Amol Chavan

Joined: Sep 04, 2005
Posts: 28
Hi All,

I have a doubt related to inheritance in Java.
I have a Class extends is created runtime and it has all the info about the tables and its

columns and field types, etc.
As more no of tables in the database size of is getting bigger &

bigger which is creating problem at the time of compilation.

So i wrote a code which will create two files at runtime like which will have info of first 50 table and which will have info of next 50 tables.
But the problem here is DBOperation is extending class so now which class it should extend?

I tried like this:

DBOperation extends Schema2

Schema2 extends Schema1

DBOperation call getTableInfo(tableName) method of its superclass which return HashMap with all the info of the table which is passed to that method.

public HashMap getTableInfo(tableName) is present in both as well

but then it is giving NullPointer Exception when DBOpereation getting information of tables which is not in Schema2 but present in Schema1.

If it is getting null from Schema2 then it must check it in
How inheritance will help in this case?

Is there any other way to do it?

How to solve this problem?
Please help me.....

Thanks n Regards,<br />Amol
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm not clear whether you're loading schema data at compile time or runtime. Is it hard coded into the class as constants or read from the database? It is possible to make a source file too large to compile, I think, but at runtime loading a lot of data into one object or two won't make much difference.

But more fundamentally, ask yourself why you're using "extends" at all. If you made a new class that just extends Object you could use composition, hold references to two Schema objects, and write a method:

You could generalize this to work on an array of Schema[] for any number of instances.

Is it really necessary that any code that works with Schema will also work with DBOperation? That's the kind of polymorphism inheritance gives you, and if it's not needed, use composition instead.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Help Me - Inheritance
It's not a secret anymore!