Create public class called myclass
Solved Step By Step with Explanation – Java Class Constructor Example
Question
Solved Step By Step with Explanation – Java Class Constructor Example
public class MyClass {
int x; // Create a class attribute called 'x'
public static void main(String[] args) {
// Create a myObj object of class MyClass
}
```
4. In the `main` method, we create an object `myObj` of the `MyClass` class using the constructor `new MyClass()`.
5. Finally, we print the value of the `x` attribute of `myObj` using `System.out.println(myObj.x)`. Since the constructor set `x` to 10, it will print `10`.