Chapter 5: Methods Flashcards
A final instance variable in Java 17 can be assigned multiple times. True or False? If false, why?
False – A final instance variable can only be assigned once: in the declaration, an instance initializer, or a constructor.
Both instance and static initializers can access static variables in Java 17. True or False?
True
A static initializer in Java 17 can access instance variables. True or False? If false, why?
False – A static initializer cannot access instance variables because it runs before any instance is created.
An instance initializer in Java 17 can assign a final instance variable. True or False? If false, why?
True
A final instance variable in Java 17 must always be initialized at the time of declaration. True or False? If false, why?
False – It can also be initialized in an instance initializer or a constructor.
A method signature in Java 17 includes the method name and parameter list. True or False? If false, why?
True
The return type is part of the method signature in Java 17. True or False? If false, why?
False – The method signature includes only the method name and parameter list, not the return type.
The access modifier of a method is required in Java 17. True or False? If false, why?
False – The access modifier is optional; a method can have default access.
A method in Java 17 must always have an exception list. True or False? If false, why?
False – The exception list is optional; methods are not required to declare exceptions.
A method in Java 17 can have an empty parameter list. True or False? If false, why?
True
Abstract methods in Java 17 must have a method body. True or False? If false, why?
False – Abstract methods cannot have a body; they are meant to be implemented by subclasses.
The method body is always required for all methods in Java 17. True or False? If false, why?
False – Abstract methods do not require a method body.
Optional specifiers like final and static are required in Java 17 method declarations. True or False? If false, why?
False – Optional specifiers are not required; methods can be declared without them.
A method declaration in Java 17 includes all necessary details to call the method. True or False? If false, why?
True
In Java 17, an access modifier controls where the method can be referenced. True or False? If false, why?
True