Java Tutorial Series - Setters and 'this' Keyword

Now we have already understood the concept of getters in Java, we will be diving deep into the concepts of setters and 'this' keyword used in Java.

Setters and 'this' keyword - 

Consider below example where we are using getters, setters and 'this' keyword.

class Frog {
private String name;
private String age;

public void setAge(int age) {
this.age = age;
}

public void setName(String Name) {
this.name = name;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public void setInfo(String name, int age) {
setName(name);
setAge(age);
}

}
public class App {

public static void main(String[] args) {
Frog frog1 = new Frog();
frog1.setName("Charlie");
frog1.setAge(22);


System.out.println(frog1.getName());
}
}

Comments

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD