Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Constructors have the same name as the ____. member methods data members class p

ID: 3803271 • Letter: C

Question

Constructors have the same name as the ____.

member methods

data members

class

package

1 points   

Question 15

When does the method finalize execute?

When the class object is created

At the start of every program

At the end of every program

When the class object goes out of scope

1 points   

Question 16

public class Secret
{
    private int x;
    private static int y;
    public static int count;
    public int z;
      
    public Secret()
    {
        x = 0;
        z = 1;
    }

    public Secret(int a)
    {
        x = a;
    }

    public Secret(int a, int b)
    {
        x = a;
        y = b;
    }

    public String toString()
    {
        return ("x = " + x + ", y = " + y + ",
                 count = " + count);
    }

    public static void incrementY()
    {
        y++;
    }
}

What does the default constructor do in the class definition in the accompanying figure?

Sets the value of x to 0

Sets the value of z to 1

Sets the value of x to 0 and the value of z to 1

There is no default constructor.

1 points   

Question 17

Consider the following statements.

public class Circle
{
   private double radius;

   public Circle()
   {
      radius = 0.0;
   }

   public Circle(double r)
   {
      radius = r;
   }

   public void set(double r)
   {
      radius = r;
   }

   public void print()
   {
       System.out.println(radius + " " + area + " "
                        + circumference);
   }

   public double area()
   {
       return 3.14 * radius * radius;
   }

   public double circumference()
   {
       return 2 * 3.14 * radius;
   }

}

Circle myCircle = new Circle();
double r;

Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input device.)

(i)
    r = console.nextDouble();
    myCircle.area = 3.14 * r * r;
    System.out.println(myCircle.area);
(ii)
       r = console.nextDouble();       
   myCircle.set(r);
   System.out.println(myCircle.area());

Only (i)      

Only (ii)

Both (i) and (ii)      

None of these

1 points   

Question 18

public class Secret
{
    private int x;
    private static int y;
    public static int count;
    public int z;
      
    public Secret()
    {
        x = 0;
        z = 1;
    }

    public Secret(int a)
    {
        x = a;
    }

    public Secret(int a, int b)
    {
        x = a;
        y = b;
    }

    public String toString()
    {
        return ("x = " + x + ", y = " + y + ",
                 count = " + count);
    }

    public static void incrementY()
    {
        y++;
    }
}

What might the heading of the copy constructor for the class in the accompanying figure look like?

public Secret(Secret s)

private copySecret()

Secret copySecret = new Secret()

public copySecret(int a, int b)

1 points   

Question 19

MysteryClass



According to the UML class diagram in the accompanying figure, which method is public and doesn’t return anything?

getCopy()

print()

equals(MysteryClass)

doubleFirst()

1 points   

Question 20

MysteryClass



According to the UML class diagram in the accompanying figure, which of the following is a data member?

MysteryClass

print()

second

getFirst

member methods

data members

class

package

Explanation / Answer

Question 14
Constructors have the same name as the __CLASS__.
Answer is option (c)

  
Question 15
Finalize method is executed At the end of every program
Answer is option (c)

      
Question 16
default constructor is public Secret(){x = 0;z = 1;}
which sets the value of x to 0 and z to 1.
Answer is option (c)


Question 17
(i)
r = console.nextDouble();
myCircle.area = 3.14 * r * r;
System.out.println(myCircle.area);
INVALID since radius is not set and the syntax of calling area method is wrond

(ii)
r = console.nextDouble();   
myCircle.set(r);
System.out.println(myCircle.area());
    VALID since value of r is taken as input and set method is called to set value if r in class and then area method called to find area of circle  

ONLY (ii) is valid
ANswer is option (b)

      

Question 18
Copy constructor is copying the values of one object of class to other  
hence, public Secret(Secret s) will be the copy constructor
ANswer is option (a)

  
Question 19
return type of print method is void
hence answer is print()
Answr is option (b)


Question 20
data memeners of the class are
first and second
answer is option (c)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote