Java
Class
public
class programmingForum{
public
programmingForum(String
forumName, String forumModerators, int forumIndex){
this.forumName = forumName;
this.forumModerators = forumModerators;
this.forumIndex = forumIndex;
}
public String
getForumName(){
return forumName;
}
public String
getForumModerators(){
return forumModerators;
}
public int
getForumIndex(){
return forumIndex;
}
}
Above is the correct way of
creating class for Java. As you can see, all my methods and
constructor are within a line called "public class
programmingForum".
That line denotes the beginning of a class.
public
programmingForum(String
forumName, String forumModerators, int forumIndex)
For this line, it is called a constructor, information will be
taken in and used to create a new object called "programmingForum",
you can have many programmingForum class object with different
forumName. It is possible to have everything the same but usually a
check is done, that would be covered later on.
String forumName, String forumModerators, int forumIndex - forumName,
forumModerators and forumIndex denotes variables that are taken to
create the new object. String and int primitive types in Java. There are many types
that are covered in another topic.
public String
getForumName(){
return forumName;
}
Notice the "String", this denotes that the METHOD will return a
string type, if you replace String with void, there is no return
type. If you leave it as String or int or double BUT you did not
return anything or return the wrong type Eg. return int for a
string. There will be compiler and runtime error respectively.