Java Chapter 8 - Designing Classes Questions
and Answers| Latest Update
Inside the class, but outside of any method body ✔️✔️Where in a class should static variables be
declared and initialized?
Before the code in the class constructor is executed ✔️✔️When are statements in a class-level
initialization block executed?
Once when the class is loaded ✔️✔️When are statements in a class-level static initialization block
executed?
If their scopes do not overlap ✔️✔️Under which conditions can you have local variables with
identical names?
The entire class in which the variable is defined ✔️✔️What is the scope of a private instance
variable?
To use a public variable or method outside of its class, you must ____ the name. ✔️✔️instantiate
The implementation of the methods will change, but the interface will not need to change
✔️✔️What will have to change if the instance variables month and day of the Date class are
replaced by the single instance integer variable dayOfTheYear?
No, unrelated classes should not be in one package ✔️✔️To make it easier to include a set of
frequently used but unrelated classes should you place them in a package?
the default package, which has no name ✔️✔️If you do not include a package statement at the
top of your class source file, its classes will be placed in which package?
, 1 2 ✔️✔️Consider the Checker class below.
public class Checker
{
public static int count = 0;
public int number = 0;
public Checker()
{
count++;
number = count;
}
public int getCount() { return count; }
public int getNumber() { return number; }
}
What is output from the code fragment below?
Checker one = new Checker();
Checker two = new Checker();
System.out.println(one.getNumber() + " " + two.getNumber());
The class that does not require an import statement at the beginning of the program that uses
it? ✔️✔️java.lang.Double
and Answers| Latest Update
Inside the class, but outside of any method body ✔️✔️Where in a class should static variables be
declared and initialized?
Before the code in the class constructor is executed ✔️✔️When are statements in a class-level
initialization block executed?
Once when the class is loaded ✔️✔️When are statements in a class-level static initialization block
executed?
If their scopes do not overlap ✔️✔️Under which conditions can you have local variables with
identical names?
The entire class in which the variable is defined ✔️✔️What is the scope of a private instance
variable?
To use a public variable or method outside of its class, you must ____ the name. ✔️✔️instantiate
The implementation of the methods will change, but the interface will not need to change
✔️✔️What will have to change if the instance variables month and day of the Date class are
replaced by the single instance integer variable dayOfTheYear?
No, unrelated classes should not be in one package ✔️✔️To make it easier to include a set of
frequently used but unrelated classes should you place them in a package?
the default package, which has no name ✔️✔️If you do not include a package statement at the
top of your class source file, its classes will be placed in which package?
, 1 2 ✔️✔️Consider the Checker class below.
public class Checker
{
public static int count = 0;
public int number = 0;
public Checker()
{
count++;
number = count;
}
public int getCount() { return count; }
public int getNumber() { return number; }
}
What is output from the code fragment below?
Checker one = new Checker();
Checker two = new Checker();
System.out.println(one.getNumber() + " " + two.getNumber());
The class that does not require an import statement at the beginning of the program that uses
it? ✔️✔️java.lang.Double