kuku
0
Q:

java create new object

Car mycar = new Car();
9

public class HelloWorld {
  public static void main(String[] args) {
    
    // how to use class in java
    class User{
    	
    	int score;
    	
    	// method that can be used outside the class
    	public boolean hasWon(){
    		if(score >= 100){
    			return true;
    		} else {
    			return false;
    		}
    	}
    }
    
    User dave = new User();
    
    dave.score = 20;
    
    System.out.println(dave.hasWon());
    
 
  }
}
2
myCar = new Car();
0
public class Puppy {
   public Puppy(String name) {
      // This constructor has one parameter, name.
      System.out.println("Passed Name is :" + name );
   }

   public static void main(String []args) {
      // Following statement would create an object myPuppy
      Puppy myPuppy = new Puppy( "tommy" );
   }
}
0
MyClass **insert_name** = new MyClass();
        insert_name.**method_name**();
0

New to Communities?

Join the community