Created
April 18, 2014 10:06
-
-
Save sivabudh/11035584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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