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

Java - 3. Analyze the following code: public class Test { public static void mai

ID: 3771079 • Letter: J

Question

Java -

3. Analyze the following code:

public class Test {

public static void main(String[] args) {

String firstName = "John";

Name name = new Name(firstName, 'F', "Smith");

firstName = "Peter";

name.lastName = "Pan";

System.out.println(name.firstName + " " + name.lastName);

}

}

class Name {

String firstName;

char mi;

String lastName;

public Name(String firstName, char mi, String lastName) {

this.firstName = firstName;

this.mi = mi;

this.lastName = lastName;

}

}

a.

The program displays Peter Pan.

b.

The program displays John Pan.

c.

The program displays Peter Smith.

d.

The program displays John Smith.

e.

None of these


ANS:

4. Analyze the following code:

public class Test {

public static void main(String[] args) {

MyDate birthDate = new MyDate(1990, 5, 6);

Name name = new Name("John", 'F', "Smith", birthDate);

birthDate = new MyDate(1991, 1, 1);

birthDate.year = 1992;

System.out.println(name.birthDate.year);

}

}

class MyDate {

int year;

int month;

int day;

public MyDate(int year, int month, int day) {

this.year = year;

this.month = month;

this.day = day;

}

}

class Name {

String firstName;

char mi;

String lastName;

MyDate birthDate;

public Name(String firstName, char mi, String lastName, MyDate birthDate) {

this.firstName = firstName;

this.mi = mi;

this.lastName = lastName;

this.birthDate = birthDate;

}

}

a.

The program displays 1990.

b.

The program displays 1991.

c.

The program displays 1992.

d.

The program displays 1993.

e.

None of these


ANS:

5. What is the output of the following code?

public class Test1 {

public static void main(String[] args) {

ChildClass c = new ChildClass();

c.print();

}

}

class ParentClass {

int id = 1;

void print() {

System.out.println(id);

}

}

class ChildClass extends ParentClass {

int id = 2;

}

a.

0

b.

1

c.

2

d.

3

e.

4


ANS:


6. What is the output of running class Test?

public class Test {

public static void main(String[] args) {

new Circle9();

}

}

public abstract class GeometricObject {

protected GeometricObject() {

System.out.print("A");

}

protected GeometricObject(String color, boolean filled) {

System.out.print("B");

}

}

public class Circle9 extends GeometricObject {

/** Default constructor */

public Circle9() {

this(1.0);

System.out.print("C");

}

/** Construct circle with a specified radius */

public Circle9(double radius) {

this(radius, "white", false);

System.out.print("D");

}

/** Construct a circle with specified radius, filled, and color */

public Circle9(double radius, String color, boolean filled) {

super(color, filled);

System.out.print("E");

}

a.

ABCD

b.

DE

c.

BEDC

d.

BEC

e.

None of these


ANS:

a.

The program displays Peter Pan.

b.

The program displays John Pan.

c.

The program displays Peter Smith.

d.

The program displays John Smith.

e.

None of these

Explanation / Answer

3. b

4. a

5. b

6. 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