Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Accessing specific class if condition is true

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accessing specific class if condition is true

    I'm making a trigonometry application with the different formulas for each shapes and such. What I wanted to know is: is there any way to make a boolean and access a specific class if this boolean is true?

    Since I'm making Degree and Radian sub-classes, I needed to make it so when the boolean isInDegrees is true, it accesses Degree class, and the inverse if isInRadian is true.


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Accessing specific class if condition is true

    Yes it is.

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Re: Accessing specific class if condition is true

    why not write a method to do this work?

    not sure if you are being told how to do something, but inheritance will handle most of your situations for you

    write the methods you need in every subclass, as well as a place holder method in the superclass (i think its something like public <returntype> <name>; that will force the subclasses to have the method "public <returntype> <name>(){//stuff}

    you make an instance of the superclass object (parent to both Degree and Radian) then call your methods, and it will automatically use the right one through the power of polymorphism. (hence no need for the booleans)

Similar Threads

  1. accessing class method problem
    By steel55677 in forum Object Oriented Programming
    Replies: 11
    Last Post: February 23rd, 2012, 08:50 PM
  2. Troubles with accessing data from outside the class.
    By broo7198 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 13th, 2011, 11:38 AM
  3. Replies: 4
    Last Post: April 27th, 2010, 01:18 AM
  4. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM
  5. [SOLVED] Problem accessing specific data in an array and getting it to return properly
    By Universalsoldja in forum Collections and Generics
    Replies: 3
    Last Post: February 4th, 2010, 04:26 PM