Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

Students also viewed these Databases questions

Question

e. What are notable achievements of the group?

Answered: 1 week ago

Question

7. Senior management supports the career system.

Answered: 1 week ago