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

Question 1 Consider the following statements. public class Rectangle { private d

ID: 3803316 • Letter: Q

Question

Question 1

Consider the following statements.

public class Rectangle
{
    private double length;
    private double width;

    public Rectangle()
    {
        length = 0;
        width = 0;
    }

    public Rectangle(double l, double w)
    {
        length = l;
        width = w;
    }

    public void set(double l, double w)
    {
        length = l;
        width = w;
    }

    public void print()
    {
        System.out.println("Length = " + length
                  + "; Width = " + width + " " +
                  + " Area = " + area()  
                  + "; Perimeter = " + perimeter());
    }

    public double area()
    {
        return length * width;
    }

    public void perimeter()
    {
        return 2 * length + 2 * width;
    }

    public void makeCopy(Rectangle otherRect)
    {
        length = otherRect.length;
        width = otherRect.width
    }
}

Rectangle tempRect = new Rectangle(14, 10);
Rectangle newRect = new Rectangle(9, 5);

What are the values of the instance variables of newRect after the following statement execute?

newRect.makeCopy(tempRect);

length = 14; width = 10

length = 9; width = 5

length = 14; width = 5

None of these

1 points   

Question 2

ADTs illustrate the principle of ____.

information hiding

privacy

encapsulation

overloading

1 points   

Question 3

MysteryClass



Which of the following would be a default constructor for the class MysteryClass shown in the accompanying figure?

public MysteryClass(){ setData(0, 0.0); }

public MysteryClass(0, 0.0) { setData(); }

public MysteryClass(0) { setData(0, 0.0); }

private MysteryClass(10){ setData(); }

1 points   

Question 4

MysteryClass



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

doubleFirst

MysteryClass

second

print

1 points   

Question 5

Which of the following class definitions is correct in Java?

(i)
   public class Employee
   {
       private String name;
       private double salary;
       private int id;

       public Employee()
       {
           name = "";
           salary = 0.0;
           id = 0;
       }

       public Employee(String n, double s, int i)
       {
           name = n;
           salary = s;
           id = i;      
       }

       public void print()
       {
           System.out.println(name + " " + id + " " + salary);
       }
   }

(ii)

   public class Employee
   {
       private String name;
       private double salary;
       private int id;

       public void Employee()
       {
           name = "";
           salary = 0.0;
           id = 0;
       }

       public void Employee(String n, double s, int i)
       {
           name = n;
           salary = s;
           id = i;      
       }

   
       public void print()
       {
           System.out.println(name + " " + id + " " + salary);
       }
   }

Only (i)      

Only (ii)

Both (i) and (ii)      

Neither is correct

1 points   

Question 6

Class members consist of all of the following EXCEPT ____.

named constants

variable declarations

pre-defined methods

methods

length = 14; width = 10

length = 9; width = 5

length = 14; width = 5

None of these

Explanation / Answer

Question 1

What are the values of the instance variables of newRect after the following statement execute?

newRect.makeCopy(tempRect);

Ans) length = 14; width = 10

_____________

Question 2

ADTs illustrate the principle of ____.

Ans)

information hiding

Question 3

Which of the following would be a default constructor for the class MysteryClass shown in the accompanying figure?

Ans) public MysteryClass(){ setData(0, 0.0); }

____________________

Question 4

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

Ans) second (in uml Private are represented with ‘-‘ symbol)

____________________

Question 5

Which of the following class definitions is correct in Java?

Ans) Only (i)     

Reason: The constructor shouldn’t return anything even void also.

_________________

Question 6

Class members consist of all of the following EXCEPT ____.

Ans)pre-defined methods

information hiding

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