1public class Puppy {
2 public Puppy(String name) {
3 // This constructor has one parameter, name.
4 System.out.println("Passed Name is :" + name );
5 }
6
7 public static void main(String []args) {
8 // Following statement would create an object myPuppy
9 Puppy myPuppy = new Puppy( "tommy" );
10 }
11}
1
2public class HelloWorld {
3 public static void main(String[] args) {
4
5 // how to use class in java
6 class User{
7
8 int score;
9
10 // method that can be used outside the class
11 public boolean hasWon(){
12 if(score >= 100){
13 return true;
14 } else {
15 return false;
16 }
17 }
18 }
19
20 User dave = new User();
21
22 dave.score = 20;
23
24 System.out.println(dave.hasWon());
25
26
27 }
28}
29