Answer to Question #152282 in Java | JSP | JSF for Hamza saeed

Question #152282
Consider the following declarations:
public class XClass
{
private int u;
private double w;
public XClass()
{
}
public XClass(int a, double b)
{
}
public void func()
{
}
public void print()
{
}
}
XClass x = new XClass(10, 20.75);
a. How many members does class XClass have?
b. How many private members does class XClass have?

Ahmad sent 16 December at 09:43
c. How many constructors does class XClass have?
d. Write the definition of the member func so that u is set to 10 and w is
set to 15.3.
e. Write the definition of the member print that prints the contents of u
and w.
f. Write the definition of the default constructor of the class XClass so
that the instance variables are initialized to 0.
g. Write the definition of the constructor with parameters of the class
XClass so that the instance variable u is initialized to the value of a and
the instance variable w is initialized to the value of b.
h. Write a Java statement that prints the values of the instance variables of x.
1
Expert's answer
2020-12-23T15:30:36-0500

Answers:

a. 6

b. 2

c. 2

d.

public void func(){
  this.u = 10;
  this.w = 15.3; 
}

e.

public void print()
{
  System.out.println(String.format("u = %d, w = %f",u,w)) 
}

f.

public XClass()
{
  this.u = 0;
  this.w = 0; 
}

g.

public XClass(int a, double b)
{
  this.u = a;
  this.w = b;
}

h.

x.print();

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog