I want to return a Course object with this method but only if the object isn't null.
public Course getClass1()
{
    if(class1 != null)
    {
        return class1;
    }
}
I have a 'missing return statement' error because it may not return anything, but I don't want to return anything, not even an empty String, if the object is null. I am okay with changing the method to a void
public void getClass1()
{
    if(class1 != null)
    {
        System.out.println(class1);
    }
}
But if I do that I can't call the methods in my toString
public String toString()
{
    return super.getName() + "\t" + super.getAge() + "\t" + getStudentNumber() +
            "\n" + getClass1() + "\n" + getClass2() + "\n" + getClass3();
}
because void types aren't allowed.
 
     
     
     
     
     
     
     
    