Results 1 to 3 of 3
  1. #1
    lakshminarayanaece2 is offline lakshminarayana
    Join Date
    May 2012
    Location
    india
    Posts
    1
    Rep Power
    0

    Default Two objects with the same name

    i am new to java .does any one say is it possible to create two objects with the same name in the class
    program code is....................

    class Test13
    {
    int a; //creating global variables a and b
    int b;
    Test13() //creating a constructor with out parameters
    {
    a=10;
    b=20;
    }
    Test13(int x,int y) //creating a constructor with parameters
    {
    a=x;
    b=y;
    }
    int mysum() // creating a function to add a and b
    {
    return a+b;
    }
    public static void main(String args[])
    {
    Test13 object=new Test13();
    Test13 object=new Test13(20,30);
    System.out.println("sum of two variables is............:"+object.mysum());
    }
    }
    Last edited by lakshminarayanaece2; 05-15-2012 at 09:47 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Two objects with the same name

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    When you have a question, start a new thread. Don't hijack another poster's thread.

    Removed from java class constructor is not executed

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Two objects with the same name

    Objects don't have names.

    What happened when you tried to compile that code?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 12
    Last Post: 04-29-2012, 02:55 PM
  2. Help with objects
    By gmoney8316 in forum New To Java
    Replies: 1
    Last Post: 05-06-2010, 02:03 AM
  3. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  4. how many objects ?
    By kevinsong in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2008, 05:59 PM

Posting Permissions

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