Question: Complete the class Myclass. public class MyClass { private int x; private static int count; MyClass() { //initialize x to 0 } MyClass(int a) {

  1. Complete the class Myclass.

public class MyClass {

private int x;

private static int count;

MyClass()

{

//initialize x to 0

}

MyClass(int a)

{

//initalize x to a

}

SetX( int a)

{

}

printX( )

{

}

public static printCount()

{

}

incrementCount()

{

}}

  1. Write the main program to test this class
  2. Declare myObject1 to be a MyClass object and initialize its instance variable x to 0.
  3. Declare myObject2 to be a MyClass object and initialize its instance variable x to 7.

  1. Use java comments to write the answers of the following questions:
    1. Which of the following statement are valid?
      1. myObject1.printCount();
      2. myObject1.printX();
      3. MyClass.printCount();
      4. MyClass.printX();
      5. MyClass.count++;

  1. What the output of the following?
    1. myObject1.printX();
    2. myObject1.incrementCount(); myObject1.printCount(); myObject2.printCount();
    3. MyClass.incrementCount(); myObject1.printCount();myObject2.printCount();
    4. myObject2.incrementCount(); myObject1.printCount();myObject2.printCount();
    5. myObject1.setX(19); myObject1.printX();myObject2.printX();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!