• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Roo
{
float length ;
float breadth ;
Roo(float x, float y)
{
length=x;
breadth=y;
}
Roo(float x)
{
length=breadth=x;
}
double area()
{
return (length * breadth);
}
}

class saisar
{
public static void main(String a[])
{
double s;
Roo obj = new Roo (4,2);
s=obj.area();
System.out.println(s);
Roo obj1 = new Roo (5);
s=obj1.area();
System.out.println(s);
}
}
Here for constructor overloading if i create 2 same
objects like
Roo obj = new Roo (4,2);
Roo obj = new Roo (5);
It is not accepting
but why the same is true for normal method overloading
i mean even i create same objects like this in method overloading it is accepting like
EXAMPLE
class e
{
float length ;
float breadth ;
double Roo(float x, float y)
{
length=x;
breadth=y;
return (0);
}
double Roo(float x)
{
length=breadth=x;
return 0;
}
double area()
{
return (length * breadth);

}
}

class saisars
{
public static void main(String a[])
{
double s;
e obj = new e ();
obj.Roo(4,5);
s=obj.area();
System.out.println(s);
obj.Roo(4);
s=obj.area();
System.out.println(s);
}
}
in this above program how can i access different method signatures with same object though data is different ? please post your comments
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by hansika motwani:

Here for constructor overloading if i create 2 same
objects like
Roo obj = new Roo (4,2);
Roo obj = new Roo (5);



Well hansika if you wrote this code as it is, then you must have got a multiple declaration error. This is because the name of the two objects are the same. You cannot declare two variables with the same name.

Also please use a meaningful title for your posts. "doubt" is not a meaningful title. The title must be explanatory of the problem in the thread....
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic