• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

void keyword

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have another problem,here's a code i just got from a book;


public class Grade
{
private String courseName(String name);

public void setCourseName(String name)
{
courseName = name;
}

public String getCourseName()
{
return courseName;
}

public void displayMessage()
{
System.out.printf("Welcome to the grade book for\n%s,getCourseName());
}

public static void main(String args[])
{
Scanner input = new Scanner(System.in);

Grade myGrade = new Grade();

System.out.println("Initial course name was Architecture");
System.out.println();

System.out.println("Please enter the course name:");
String name = input.nextLine();
myGrade.setCourseName(name);
System.out.println();
myGrade.displayMessage();
}
}



setCourseName,considering the fact that it is void which means it shouldnt return any data when it completes task,but in this case i think it does cos the method's being called from the main method(myGrade.setCourseName) and thats when the program prompts you to enter course name after executing.after keying in the course name data is then returned to the system for the line "Welcome to the grade book for ......" to display when the displayMessage is invoked.am i right?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"...but in this case i think it does cos the method's being called from the main method(myGrade.setCourseName)"

No, the setCourseName(...) method does not return any data. It can't because it's declared as void. The method does change the state of the Grade object that you're calling it on, but it does not return a value. Are you confusing those two concepts?
 
reply
    Bookmark Topic Watch Topic
  • New Topic