Click here to Skip to main content
12,559,389 members (50,833 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
What can directly access and change the value of the variable roomNr?
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.

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?
Locale l = Locale.getDefault();
System.out.println(l.getDisplayCountry() + " " + df.format(d));
Locale l = Locale.getLocale();
Locale l = Locale.getLocale();
System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));
Locale l = Locale.getDefault();
System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));

What is true about objects referenced by a, b, aa at the line labeled "// some code goes here"?
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.

What do you need to do to correct compilation errors? (Select two)
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
Updated 24-Jan-13 0:58am
Nagy Vilmos313.7K
Nagy Vilmos 24-Jan-13 6:47am
This, and the other two 'questions' are very dubious and appear to be homework.
I will delete the other two and move them here.
Nagy Vilmos 24-Jan-13 6:59am
That's four questions you've asked. These are very simple Java principles, please re-read your course books and speak to your teacher if you cannot do these problems.
H.Brydon 11-Mar-13 20:33pm
Just curious ... where is your school?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
Nagy Vilmos 24-Jan-13 7:45am
This is why I put all four together, it's a POP.
OriginalGriff 24-Jan-13 7:52am
Pathetic Original Poster! :laugh:
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Uhm... Yeah.
Easy stuff,

Q1: b)
Q2: a)

Aaah, I just seen Nagys POP comment.
No. I don't do your homework.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 11 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100