Click here to Skip to main content
15,896,154 members

Do my homework for me

Revision 6
Q1
What can directly access and change the value of the variable roomNr?
Java
package com.mycompany;
 
public class Hotel {
public int roomNr = 100;
}


A) Only the Hotel class.
B) Any class.
C) Any class in com.mycompany package.
D) Any class that extends Hotel.
_____

Q2
Given:
d is a valid, non-null java.util.Date object
df is a valid, non-null java.text.DateFormat object set to the current locale.
What outputs the current locale's country name and the appropriate version of date?
A)
Java
Locale l = Locale.getDefault();
System.out.println(l.getDisplayCountry() + " " + df.format(d));

B)
Java
Locale l = Locale.getLocale();
System.out.println(l.getDisplayCountry());

C)
Java
Locale l = Locale.getLocale();
System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));

D)
Java
Locale l = Locale.getDefault();
System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));

_____

Q3
What is true about objects referenced by a, b, aa at the line labeled "// some code goes here"?
Java
class A {
    private B b;
    public A() {
        this.b = new B(this);
    }
}

class B {
    private A a;
    public B(A a) {
        this.a = a;
    }
}

public class Test { 
    public static void main(String args[]) {
        A aa = new A();
        aa = null;
        // some code goes here
    }
}

A) The objects referenced by a and b are eligible for garbage collection.
B) None of these objects are eligible for garbage collection.
C) Only the object referenced by "a" is eligible for garbage collection.
D) Only the object referenced by "b" is eligible for garbage collection.
E) Only the object referenced by "aa" is eligible for garbage collection.
_____

Q4
What do you need to do to correct compilation errors? (Select two)
Java
public class Creature {
private int legCount;
private int wingCount;

public Creature(int legCount) {
this.legCount = this.legCount;
this.wingCount = 0;
}

public String toString() {
return "legs=" + this.legCount + " wings=" + wingCount;
}
}

public class Animal extends Creature {
public Animal(int legCount) {
this.wingCount = 0;
}

}

A) insert a call to super() into Creature constructor.
B) insert a call to super() into Animal constructor.
C) insert a call to this() into Animal constructor.
D) insert a call to super(legCount) into Animal constructor.
E) change the wingCount variable in the class Creature to protected.
F) change the string "this.wingCount = 0" in the class Animal to "super.wingCount = 0"
Posted 24-Jan-13 0:10am by Narendrareddy07.
Tags: