Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created April 18, 2014 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/11035584 to your computer and use it in GitHub Desktop.
Save sivabudh/11035584 to your computer and use it in GitHub Desktop.
public class StudentScore {
public String id;
public int score;
/*
// Constructor
0) The name of the method has to be the same as the class name
1) Has no return type
2) Automatically called whenever you "new" a class
3) You can have multiple constructors as long as "signature" different
*/
// This is an example of "constructor"
StudentScore() {
System.out.println("I'm inside an empty constructor!");
}
// Another example of constructor
StudentScore(String newId, int newScore) {
System.out.println("I'm inside a constructor!");
id = newId;
score = newScore;
}
// Here's an example of a regular method
public static int a(int x, int y)
{
return x + y;
}
public static void main(String[] args) {
StudentScore s1 = new StudentScore();
StudentScore s2 = new StudentScore("123", 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment