CMSC 132 EXAM #1(All solved)
Classes can only extend more than one other class if at least one of those classes is an abstract class. correct answers False - a Class can never extend more than one class. Downcasting can be done implicitly. correct answers False - it must be done explicitly or your code will not compile. "Sideways" casting is never allowed correct answers True '' will refer to the current object, treating it as an instance of the parent of the parent of the current class. correct answers True. For example, if class C extends class B, which extends class A, then calling "String()" from within class C will return the result of A's toString method. Constructors in subclasses must directly invoke the constructors of every single parent class before initializing the instance variables unique to that subclass. correct answers False - usually, a single call to the constructor of the immediate superclass is needed, however. This is done with the keyword 'super' and must be the first line in the constructor. . Assume there is a method named foo in a superclass A, which has been overridden in B (a subclass of A). If () is called from within class B, it will run the foo() method from class A, but if foo() is called from within class B, it will run the foo() method from class B. correct answers True Every class is a subclass of Object. correct answers True - note that this question doesn't necessarily mean that the class is ONLY a subclass of Object, but every class does inherit from Object, either directly or indirectly. When you override a method, you are allowed to change the number of arguments. correct answers False - the method signature must be exactly the same When you overload a method, you are allowed to change the number of arguments. correct answers True To sort an ArrayList of MyObject objects using C, MyObject must have an implementation of the compareTo method defined in the class. correct answers False - you can also pass in a Comparator with the compare method. Unchecked exceptions are generally for common exceptions that need to be accounted for. correct answers False - this is describing checked exceptions, not unchecked exceptions. An abstract class must include at least one abstract method. correct answers False An abstract class can contain instance variables and constructors. correct answers True
Información del documento
- Subido en
- 28 de mayo de 2024
- Número de páginas
- 7
- Escrito en
- 2023/2024
- Tipo
- Examen
- Contiene
- Preguntas y respuestas