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

Given the following code, what is output by the method call, mystery(6 * 8)? pub

ID: 3797847 • Letter: G

Question

Given the following code, what is output by the method call, mystery(6 * 8)?

public static void mystery (int x[]) {
    System.out.println("A");
}
public static void mystery (int x) {
    System.out.println("B");
}
public static void mystery (String x) {
    System.out.println("C");
}

A

B

C

CA

CB

Which of the following is true about overloaded methods?

Java cannot use a method's return type to tell two overloaded methods apart.

Java cannot use a method's parameters to tell two overloaded methods apart.

You can only overload methods that have parameters.

All overloaded methods must have different names.

None of the above

Given the following code, what is output by the method call, mystery (5, 7.0015)?

public static void mystery (int a) {
    System.out.println("A");
}

public static void mystery (double a) {
    System.out.println("B");
}

public static void mystery (int a, double b) {
    System.out.println("C");
}

public static void mystery (double a, int b) {
    System.out.println("D");
}

A

B

C

D

Nothing is printed - there is an error.

Consider the following methods:

public static double doStuff(int a) {
    return a/2;
}
public static double doStuff(double val) {
    return val/10;
}

What is output by the following?

System.out.println(doStuff(5) + doStuff(5.0));

2.00.5

2.50.5

22.5

2.5

5

What is output to the screen by the following code?

System.out.println("Sum=" + 4 + 5);

Sum= 5 4

Sum=45

Sum=9

Sum= 4 5

Sum=54

What is output to the screen by the following code?

System.out.print(21/5);

3.5

4

4.2

5

5.5

Consider the following three classes: Clothing, Socks, and Sweater. Which would you choose be an abstract class?

Clothing

Socks

Sweater

Socks and Sweater

all of the above

Which of the following keywords allows a child class to access the overridden methods in a parent class?

extends

new

super

this

None of the above

Questions 9 and 10 refer to the following code:

public abstract class Phone {
    abstract void dial();    
}

public class MobilePhone extends Phone {
    
}

public class RotaryPhone extends Phone {
    public void dial () {
        //code not shown
    }
}

Which of the following statements is true?

RotaryPhone can be instantiated.

MobilePhone can be instantiated.

RotaryPhone cannot be instantiated.

Neither can be instantiated since you cannot extend an abstract class.

Neither can be instantiated since they do not include constructors.

Which of the following statements is true?

A Phone object can access methods in MobilePhone.

A RotaryPhone object can access methods in MobilePhone.

RotaryPhone inherits from Phone and MobilePhone.

RotaryPhone inherits from Phone.

None of the above.

Suppose a class implements the Comparable interface. Which of the following methods must the class include?

length

charAt

substring

indexOf

compareTo

Questions 12-14 refer to the following:

public class A {
    public A () {
        System.out.print(“one ”);
    }

    public A (int z) {
        System.out.print(“two ”);
    }

    public void doStuff() {
        System.out.print(“six ”);
    }
}

public class B extends A {
    public B () {
        super ();
        System.out.print(“three ”);
    }

    public B (int val) {
        super (val);
        System.out.print(“four ”);
    }
}

What is printed when the following line of code is executed?

B b = new B();

one three

two four

four two

three two

one four

What is printed when the following line of code is executed?

A a = new B(5);

four

two four

one

two

four one

Assume that variable b has been instantiated as a B object. What is printed when the following line of code is executed?

b.doStuff();

six

four

five

two

three

Which of the following is true about interfaces:

All methods in an interface must be abstract.

A class can only implement one interface.

An interface can have only non abstract methods.

Can not contain constants but can have variables.

None of the above.

What is the rule for a super reference in a constructor?

It must be in the parent class' constructor.

It must be the last line of the constructor in the child class.

It must be the first line of the constructor in the child class.

Only one child class can use it.

You cannot use super in a constructor.

Consider the following class definition.

public class WhatsIt {
    private int length;
    private int width;


    public int getArea () {
        // implementation not shown
    }

    private int getPerimeter () {
        // implementation not shown
    }
}

A child class Thingy that extends WhatsIt would have access to:

getArea()

getPerimeter()

width, length, getPerimeter()

width, length, getArea()

all of the above

Questions 18 - 20 pertain to the following class, Point:

public class Point {
    private double x;
    private double y;

    public Point() {
        this (0, 0);
    }

    public Point(double a, double b) {
        /* missing code */
    }
    // ... other methods not shown
}

Which of the following correctly implements the equals method?

public boolean equals(Point p) {
    return (x == Point.x && y == Point.y);
}

public void equals(Point p) {
    System.out.println(x == p.x && y == p.y);
}

public boolean equals(Point p) {
    System.out.println(x == p.x && y == p.y);
}

public boolean equals(Point p) {
    return (x == p.x && y == p.y );
}

public void equals(Point p) {
    return (x == p.x && y == p.y );
}

The default constructor sets x and y to (0, 0) by calling the second constructor. What could be used to replace /* missing code */ so that this works as intended?

a = 0;
b = 0;

this(0, 0);

this (x, y);

a = x;
b = y;

x = a;
y = b;

Which of the following correctly implements a mutator method for Point?

public double getX() {
    return x;
}

public double getX() {
    return a;
}

public void setCoordinates (double a, double b) {
    x = a;
    y = b;
}

public void setCoordinates (double a, double b) {
    Point p = new Point(a,b);
}

None of the above

Explanation / Answer

Q1- output will be C because the parameter we pass are nether an integer nor an array it is combination of operator and operand so it is considered as string.
Q2-you can only overload method that have parameters because without parameters method overloading cannot be done because for method overloading the condition is the method an have same name but with diffrent parameters or diffrent parameters list .
Q3-Output will be c because the parameters we passed are int and double so 3rd method will be called .
Q4-output will be 2.5 becuase first method returns 2 and second method returns 0.5 and both add up to print 2.5
Q5-output will be sum=45 because it appends the numbers 4 and 5 and not add them.
Q6-output will be 4 because default type is int so it will display only integer part and not the decimal values.
Q7-Clothing will be an abstract class because the methods for socks and sweater can be just declared in the clothing class and then can be defined in the respected socks and sweater classes.
Q8-extends keyword alows to do so because when we inherit class then only we can override a method and inheritance is done through extend keyword.
Q9-RotaryPhone can be instantiated because it has defined the method declared in the abstrct class.
Q10- RotaryPhone inherits from Phone as it is extending phone class only .
Q11-compareTo() must be included in the class as it is used to compare two objects.
Q12-one three is printed as b object is created without parameters so default parameter is called as in that default parameter of A is also called by super();.
Q13-two four is printed because now object of b is passed with a value so parameterized constructor is called .
Q14-six will be printed as b extends a.
Q15-Can not contain constants but can have variables.
Q16-It must be the first line of the constructor in the child class.
Q17-only getArea() can be accessed because other method and members are private so they cannot be accssed directly.
Q18-public void equals(Point p) {
System.out.println(x == p.x && y == p.y);
}
Q19-this (x, y);

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