I have always returned single field with getter methods, I was wondering if we can return Object using getter.
I have,
class Student
{
int age
String name
public Student(int age,String name)
{
this.age=age;
this.name=name;
}
public Student getStudent()
{
// **how can I do this**
return studentObject;
}
I have used ,
public int getAge()
{
return age;
}
many times I need to know how to do with Object Or even we can do it or not.
studentObjectshould be. Right now, it's not very clear what exactly you're asking.getStudent()return a new object with new or different parameters, simply the same object, or a single instance? CangetStudentbe static? Also: meta.stackexchange.com/questions/66377/what-is-the-xy-problem