Hello everyone, i was reading java tutorials on the internet then i saw this program,
class Cat {
private String mCatName;
Cat(String name) {
mCatName=name;
}
public String getName() {
return mCatName;
}
public void setName(String strName) {
mCatName = strName;
}
public void messWithCat(Cat kitty) {
kitty = new Cat("Han");
}
public void changeKitty(Cat kitty) {
kitty.setName("Wookie");
}
Cat haveKitten()
{
Cat kitten = new Cat("Luke");
return kitten;
}
}
class abc {
public static void main (String args[]){
Cat cat1 = new Cat("Jabba");
Cat cat2 = new Cat("Leia");
cat1.getName();
cat2.getName();
messWithCat(cat1);
changeKitty(cat2);
Cat cat3 = haveKitten();
cat1.getName();
cat2.getName();
cat3.getName();
}
}
inside class Cat,
what is this ?
public void messWithCat(Cat kitty) {
kitty = new Cat("Han");
}
public void changeKitty(Cat kitty) {
kitty.setName("Wookie");
}
Cat haveKitten()
{
Cat kitten = new Cat("Luke");
return kitten;
}
they look like objects but how they have been created in the same class ? and please explain what is this ?
also when i run this program i am getting this error,
E:\Java\bin>javac abc.java
abc.java:41: cannot find symbol
symbol : method messWithCat(Cat)
location: class abc
messWithCat(cat1);
^
abc.java:42: cannot find symbol
symbol : method changeKitty(Cat)
location: class abc
changeKitty(cat2);
^
abc.java:43: cannot find symbol
symbol : method haveKitten()
location: class abc
Cat cat3 = haveKitten();
^
3 errors
please explain this.