Test
Java Exam 2 Prep
Crea una cuenta gratis para terminar este test
Guarda tu progreso y consulta tu resultado final.
¿Ya tienes cuenta? Inicia sesión
Preguntas del test (56)
1An abstract class may contain instance fields, but an interface can't have any instance fields (variables).
- AVerdadero
- BFalso
2An abstract class needs to have at-least one abstract method.
- AVerdadero
- BFalso
3An abstract method cannot be placed in a non-abstract class.
- AVerdadero
- BFalso
4An abstract class cannot be instantiated, but any class extending an abstract class can be instantiated.
- AVerdadero
- BFalso
5A class extending an abstract class needs to implement every abstract method in the abstract class. However, overriding non-abstract methods of the abstract class is optional.
- AVerdadero
- BFalso
6Although an abstract class cannot be instantiated, but it can have constructors.
- AVerdadero
- BFalso
7An interface in Java can have both method declarations and method implementations.
- AVerdadero
- BFalso
8A Java class can implement multiple interfaces.
- AVerdadero
- BFalso
9In Java, can an interface have variables (fields)?
- ANo, interfaces can only have methods
- BYes, but the variables must be static and final
- CYes, interfaces can have instance variables
- DYes, but variables in an interface are automatically initialized
10In Java, a class can extend both another class and implement one or more interfaces.
- AVerdadero
- BFalso
11Which keyword is used to define an interface in Java?
- Aclass
- Babstract
- Cinterface
- Dimplements
12Which of the following keywords is used by a class to implement an interface in Java?
- Ainterface
- Buse
- Cextends
- Dimplement
13An interface can extend another interface in Java.
- AVerdadero
- BFalso
14What happens if a class claims to implement an interface but doesn't provide implementations for all the interface's methods?
- AThe class will throw a runtime exception when an unimplemented method is called.
- BThe compiler will automatically generate method implementations for the class.
- CThe class will inherit default implementations for unimplemented methods.
- DThe code will not compile.
15What is an abstract class in Java?
- AA class with no methods
- BA class that cannot be instantiated
- CA class that is marked as "final"
- DA class that is entirely static
16An abstract class in Java can have both abstract and concrete (implemented) methods.
- AVerdadero
- BFalso
17A class that extends an abstract class must implement all the abstract methods defined in that class.
- AVerdadero
- BFalso
18Multiple Choice: What is an abstract method in Java?
- AA method that has no return type
- BA method that is marked as "private"
- CA method that is declared but has no implementation
- DA method that is marked as "final"
19In Java, can a class extend multiple abstract classes?
- AYes, Java supports multiple inheritance with abstract classes.
- BNo, a class can only extend one abstract class.
- CIt depends on the version of Java being used.
- DYes, but you need to use the "implements" keyword.
20Abstract methods must be declared with the "abstract" keyword and cannot have method bodies.
- AVerdadero
- BFalso
21Which of the following keywords is used by a subclass to inherit from an abstract class in Java?
- Aextend
- Bimplement
- Cinherit
- Duse
22An inner class can access private members of the outer class in Java.
- AVerdadero
- BFalso
23What is the primary advantage of using inner classes in Java?
- AThey allow for multiple inheritance in Java.
- BThey improve encapsulation and code organization.
- CThey reduce code complexity.
- DThey provide access to private members of the outer class.
24What is a local inner class in Java?
- AA class defined within a method or a code block
- BAn inner class that cannot be extended
- CAn inner class that is marked as "final"
- DAn inner class that is defined within a package-private class
25An inner class can be instantiated without an instance of the outer class.
- AVerdadero
- BFalso
26A static inner class can access non-static members of the outer class without an instance of the outer class.
- AVerdadero
- BFalso
27Inner classes are always inherited by subclasses of the outer class.
- AVerdadero
- BFalso
28Inner classes can be marked as "final" in Java.
- AVerdadero
- BFalso
29Which class in Java is commonly used for reading input from the keyboard?
- AScanner
- BSystem
- CInputStream
- DBufferedReader
30What is the purpose of the System.out object in Java?
- AReading data from the console
- BWriting data to the console
- CReading data from a file
- DWriting data to a file
31Which Java class is often used for reading data from an input stream in a character-based manner?
- AFileInputStream
- BFileReader
- CBufferedReader
- DDataInputStream
32What is the purpose of the BufferedWriter class in Java?
- AReading data from a file
- BWriting data to a file
- CReading data from the console
- DWriting data to the console
33Which method in Java is used to write data to a file?
- Awrite()
- Bread()
- Cinput()
- Doutput()
34The System.in object is used for writing data to the console.
- AVerdadero
- BFalso
35The FileInputStream class is suitable for reading text data from a file.
- AVerdadero
- BFalso
36In Java, the PrintWriter class is commonly used for formatted text output.
- AVerdadero
- BFalso
37When using the Scanner class for input, you must import it from the java.util package.
- AVerdadero
- BFalso
38In Java, the readLine() method is used to read a line of text from the console.
- AVerdadero
- BFalso
39What is an exception in Java?
- AAn error in the code that prevents it from compiling
- BAn unexpected event or error that occurs during program execution
- CA statement that intentionally halts the program
- DA reserved keyword to handle errors
40Which keyword is used to throw an exception explicitly in Java?
- Araise
- Bthrow
- Ctry
- Dcatch
41What is the purpose of the try block in Java exception handling?
- ATo define the code that might throw an exception
- BTo catch and handle exceptions
- CTo specify the type of exception that will be thrown
- DTo re-throw an exception
42Which keyword is used to catch and handle exceptions in Java?
- Atry
- Bcatch
- Cthrow
- Dfinally
43What is the purpose of the finally block in Java exception handling?
- ATo define the code that might throw an exception
- BTo specify the type of exception that will be thrown
- CTo catch and handle exceptions
- DTo specify code that is always executed, whether or not an exception is thrown
44The catch block in Java can catch multiple types of exceptions by specifying them in a single block.
- AVerdadero
- BFalso
45It is a good practice to catch exceptions without providing any specific handling code, as the JVM will handle them by default.
- AVerdadero
- BFalso
46The throws keyword is used to throw an exception in Java.
- AVerdadero
- BFalso
47What is the purpose of the final keyword when used with a variable in Java?
- AIt specifies that the variable cannot be changed after initialization.
- BIt makes the variable a class variable.
- CIt allows the variable to be accessed from other classes.
- DIt specifies that the variable can only be accessed within a method.
48Which of the following statements is true about a static variable in Java?
- AIt is an instance variable and belongs to an instance of the class.
- BIt is used for local variables within a method.
- CIt is a class variable and belongs to the class itself.
- DIt is a reserved keyword for defining variables.
49In Java, which keyword is used to declare a constant variable that can be shared across instances of a class?
- Aconst
- Bfinal
- Cstatic
- Dvariable
50A final variable can be assigned a value only once and cannot be changed afterward.
- AVerdadero
- BFalso
51A static variable is associated with an instance of the class and is unique to each instance.
- AVerdadero
- BFalso
52You can access a static variable using an instance of the class, but it is generally recommended to access it using the class name.
- AVerdadero
- BFalso
53What is the purpose of the final keyword when used with a method in Java?
- AIt specifies that the method cannot be overridden by subclasses.
- BIt makes the method public and accessible from other classes.
- CIt allows the method to be overloaded with different parameter types.
- DIt makes the method asynchronous.
54Which of the following statements is true about a static method in Java?
- AIt is an instance method and belongs to an instance of the class.
- BIt can be overridden by subclasses.
- CIt is a class method and can be called using the class name.
- DIt is not accessible from other classes.
55A final method can be overridden by subclasses.
- AVerdadero
- BFalso
56A static method can be called on an instance of the class but is more commonly called using the class name.
- AVerdadero
- BFalso
Información
- Descripción
- Computer Science Test sobre Java Exam 2 Prep, creado por Eric Brletic el 02/11/2023.
- Autor
- Eric Brletic
- Idioma
- English
- Visitas
- 15
- Etiquetas
- Valoración
- Aún sin valoraciones Valora este test