Results 1 to 2 of 2
  1. #1
    Denis2k11 is offline Member
    Join Date
    Oct 2012
    Rep Power

    Exclamation Object casting trouble?

    So I have some code for a project with four classes, all of which are extended by a super class. The super class is building, the sub classes are church, hospital, library and school. I want to check if the login details for the church etc are correct and to return that specific user. However, without having four seperate methods. Is there a way to return a generic building and cast it into the sepcific building??

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Object casting trouble?

    Well, assuming I understand your problem, you could have a single method in the super class and within that method, check to see what type of instance is invoking it. But a better approach is to provide a login method in the super class and override it as appropriate in the sub classes. Making your login method in building abstract or implementing a login interface would ensure the method is implemented.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Object Casting
    By allaudin in forum New To Java
    Replies: 5
    Last Post: 07-25-2013, 07:06 PM
  2. Need help with Object Casting
    By Elaforestis in forum New To Java
    Replies: 6
    Last Post: 10-17-2012, 10:05 PM
  3. Casting a String object to a Form object
    By kakinyim in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-23-2011, 11:41 AM
  4. Object casting
    By spiderweb in forum Advanced Java
    Replies: 5
    Last Post: 08-20-2009, 05:43 PM
  5. Object to Int casting
    By nn12 in forum New To Java
    Replies: 4
    Last Post: 12-06-2008, 10:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts