| Claim | Verdict |
|---|
| A class holds both the blueprint and the data | False. The class is the blueprint; data lives on objects. |
| A constructor is a method | False. It has no return type and is called by new. |
| Constructors are inherited | False. Subclasses must declare their own. |
| A top-level class can be private | False. Only public or package-private. |
| One class per file is required | False. Only one may be public. |
| A static field has one copy per object | False. There is exactly one copy per class. |
| A class must be used before it is declared | False. Class names resolve regardless of order. |
| Interfaces and abstract classes are interchangeable | False. Only abstract classes can hold state. |
Frequently Asked Questions
What is the difference between a class and an object?
A class is a blueprint defined once in your source code, describing the fields and methods its objects will have. An object is a concrete instance created from that class, holding its own copy of every instance field and living on the heap until it becomes unreachable.
What can a class contain?
Instance and static fields, instance and static methods, constructors, static and instance initializer blocks, and nested types including nested classes, interfaces, enums, and records. Nested types can have any access modifier, while a top-level class is limited to public or package-private.
Why can a top-level class not be private?
Because a top-level class has no enclosing scope, so private would have no meaning. That restriction is exactly why nested classes are useful, since a nested class sits inside another class and can therefore be private, protected, public, or package-private as the situation requires.
Must the file name match the class name?
Only when the class is public. A public class must live in a file whose name matches it exactly, including case, so the compiler can locate it without scanning. A file may contain any number of additional package-private classes whose names can differ freely.
Why does a constructor not have a void return type?
Because Java distinguishes them syntactically. A member whose name matches the class and which has no return type is a constructor and is invoked by new. Adding void, even once, turns it into an ordinary method that returns nothing, and the class then silently has no constructor of that signature.
Are constructors inherited?
No. A subclass does not receive its parent constructors. If the parent declares no no-argument constructor, the compiler generates a default super call for you, and if it declares constructors with parameters you must call one of them explicitly using super.
What is the difference between a static field and an instance field?
An instance field has one copy per object, so each object holds its own value. A static field belongs to the class, so exactly one copy exists regardless of how many objects you create. Static fields are shared, which also makes them shared across threads and a common source of race conditions.
Can I reference a class before its declaration in the file?
Yes. Class names are resolved by name rather than by position, so using a class declared further down the same file is perfectly legal. Field and variable access is different: reading a field before its declaration is a compile error, because those must appear in textual order.