Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following definition of the class Sample: publicclassSample { privatelongint x; privatedouble y; publicSample() { } publicSample(int a, double b) { } publicvoidsetSample() {

Consider the following definition of the class Sample:

publicclassSample

{

privatelongint x;

privatedouble y;

publicSample()

{

}

publicSample(int a, double b)

{

}

publicvoidsetSample()

{

}

publicvoidprint()

{

}

}

a.How many constructors does class Sample have?

Show the answer:

b.Write the definition of the member setSample so that x is set to 10 and y is set to 25.8.

Show the answer:

c.Write the definition of the member print that prints the contents of x and y.

Show the answer:

d.Write the definition of the default constructor of the class Sample so that the instance variables are initialized to 0.

Show the answer:

e.Write the definition of the constructor with parameters of the class Sample so that the instance variable x is initialized to the value of a and the instance variable y is initialized to the value of b.

Show the answer:

f.Write Java statement that creates the Sample object s and initializes the instance variables of s to your school id and 35.0, respectively.

Show the answer:

g.Write Java statement that prints the values of the instance variables of s.

Consider the following definition of the class MyClass:

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions