Passing an object in java is interesting concept - you can pass a whole object to a method.
class Bollywood
{
void bset(Hollywood h)
{
h.hset("Pyar kiya to darna kya");
}
}
class Hollywood
{
String movie;
public void hset(String m)
{
movie=m;
}
public String hshow()
{
return movie;
}
}
class object_passing_example
{
public static void main(String args[])
{
Hollywood obj1=new Hollywood();
obj1.hset("A walk to remember");
System.out.println(obj1.hshow());
Bollywood obj2=new Bollywood();
obj2.bset(obj1);
System.out.println(obj1.hshow());
}
}
class Bollywood
{
void bset(Hollywood h)
{
h.hset("Pyar kiya to darna kya");
}
}
class Hollywood
{
String movie;
public void hset(String m)
{
movie=m;
}
public String hshow()
{
return movie;
}
}
class object_passing_example
{
public static void main(String args[])
{
Hollywood obj1=new Hollywood();
obj1.hset("A walk to remember");
System.out.println(obj1.hshow());
Bollywood obj2=new Bollywood();
obj2.bset(obj1);
System.out.println(obj1.hshow());
}
}
No comments:
Post a Comment