Thread: Oop Variables

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Oop Variables


    Hello,
    I am trying to do a object oriented program.
    My code is:


    public class OOP
    {
    public static void main(String[] args)
    {
    //person oriented based
    String name;
    String dob;
    int age;


    }
    }

    The variables are not written in green so when i try to call upon it in this code:

    public class Practice
    {
    public static void main(String[] args)
    {
    OOP person1 = new OOP();
    OOP person2 = new OOP();
    OOP person3 = new OOP();

    person1.name = "Bob";

    }
    }

    The .name isn't being recognized. What should I do?
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    You have two main functions. Main function is normally used in one class as starting entry function.

    In the OOP class, you should remove the main function and not have the variables inside a a function.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    15
    Rep Power
    0
    You should also use the public modifier for the variables in the OOP class.

IMN logo majestic logo threadwatch logo seochat tools logo