Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2007, 04:13 PM
Member
 
Join Date: Jul 2007
Posts: 26
romina is on a distinguished road
I want to add function
Hi, i have following code:

Code:
public class Building { protected String name; A(String name){ this.name = name; } public void printSpecs() {} }
and two inherited classes :


Code:
public class House extends Building { protected double maxDimension; House (String name, double maxDimension) { super(name); this.maxDimension= maxDimension; } public void printSpecs() { System.out.println(maxDimension); } } public class Castle extends Building { protected double maxWeight; Castle (String name, double maxWeight) { super(name); this.maxDimension= maxWeight; } public void printSpecs() { System.out.println(maxWeight); } }
I have array of objects
Code:
HashMap <int, Building > builds = new HashMap<int, Building >();
and some of them are of type "House" and some "Castle"

when i do following:
Code:
Building myBuild = builds .get(x); myBuild.printSpecs();
everything works: specs are printed according to class type.

Now, the question: I want to add function
Code:
int GetSpecs() {}
to "father" class "Building" so that result will be returned by inherited class (similar to function printSpecs)
But, when i add such empty function i get error "function GetSpecs must return results".
So, what's the right syntax/way to do it ?
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 06:25 AM
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
The reason it asks for a return type is because you can't have an empty method with a return type of int.

Code:
int GetSpecs() {}
You could only do this if the class was abstract (if I remember right). but if it was abstract then you would want to implement it in the child classes.

Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
use of onclick function m4tt New To Java 1 02-16-2008 04:03 AM
How to use a function in java olikhvar New To Java 2 02-16-2008 03:57 AM
Need a little help with a function! Nuluvius New To Java 3 02-08-2008 12:33 AM
function name osval Advanced Java 1 08-06-2007 09:56 PM
Help with the Dummy Function Felissa JavaServer Pages (JSP) and JSTL 1 07-06-2007 06:03 PM


All times are GMT +3. The time now is 12:18 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org