| 
  
   Menu 
  × 
      
    × 
      Correct! 
    Exercise:Create and call a class constructor of  
// Create a MyClass class
public class @(7) {
  int @(1);  // Create a class attribute x
  // Create a class constructor for the MyClass class
  public @(7)() {
    x = @(1);  // Set the initial value for the class attribute x to 5
  }
  public static void main(String[] args) {
    // Create an myObj object of class MyClass (This will call the constructor)
    MyClass @(5) = new MyClass(); 
    // Print the value of x
    System.out.println(@(5).@(1));
  }
}
 
// Create a MyClass class
public class MyClass {
  int x;  // Create a class attribute x
  // Create a class constructor for the MyClass class
  public MyClass() {
    x = 5;  // Set the initial value for the class attribute x to 5
  }
  public static void main(String[] args) {
    // Create an myObj object of class MyClass (This will call the constructor)
    MyClass myObj = new MyClass(); 
    // Print the value of x
    System.out.println(myObj.x);
  }
}
 
    Not CorrectClick here to try again. Correct!Next ❯ | 
This will reset the score of ALL 59 exercises.
Are you sure you want to continue?