• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

doubt

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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....
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic