






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This study guide covers key concepts and programming principles in java, focusing on topics like static programming analysis, object-oriented programming, generics, and polymorphism. It includes multiple-choice questions and answers, providing a comprehensive review for the csc 300 exam 1 and final exam. The guide is particularly useful for students seeking to solidify their understanding of java fundamentals and prepare for assessments.
Typology: Exams
1 / 30
This page cannot be seen from the preview
Don't miss anything!
Static programming analysis includes all of the following except.
A. Finding programming errors B. Capturing run-time divide by zero exception. C. Calculating cyclical complexity. D. Identifying unused code. - Correct: ✔✔Capturing run-time divide by zero exception. The output of the JVM is _______ - Correct: ✔✔Native machine code What is the name of the class that is the ancestor to every other class in Java? ________ - Correct: ✔✔Object The interface Comparator contains the method ___________ - Correct: ✔✔compare Which statement is true about subclasses? ___________ A. They can override constructors. B. They can only call the default constructor of the super class. C. They can override abstract methods of the superclass.
D. They inherit the public methods of the parent class.. - Correct: ✔✔They can override abstract methods of the superclass or they inherit the public methods of the parent class How many interfaces can a Java class implement? ___________ - Correct: ✔✔Unlimited How many copies of "cook" are created in the String Constant Pool if you execute the following statement ___________ String x = "cook"; String y = "cook"; String z = new String("cook"); - Correct: ✔✔ 1 What is the following code snippet an example of: ___________
extends Number> - Correct: ✔✔upper bounded wildcard type What is polymorphism in Java? ___________ A. It is when a single parent class has many child classes. B. It is when a class has several methods with the same name but different parameter types. C. It is when a single variable is used with several different types of related objects at different places in a program. D. It is when a program uses several different types of objects, each with its own variable. - Correct: ✔✔It is when a single variable is usedList < int > intList = new ArrayList < > (); intList.add(10); intList.add(20); System.out.printf("The list is: %s\n", intList); } } A. It prints the following: The list is: [10, 20] B. It prints the following: The list is: [20, 10] C. It results in a compiler error D. It results in a runtime exception - Correct: ✔✔it results in a compile error Based on the class definition below, what can be inferred about the following class B: ___________public class B
Given the following definitions, which assignments are legal?
class Box
A. They can override constructors. B. They can overload concrete methods of the superclass. C. They can override abstract methods of the superclass. D. They can overload abstract methods of the superclass. - Correct: ✔✔They can override constructors How many subclasses can a Java class have? ___________ - Correct: ✔✔Unlimited What is the following code snippet an example of: ___________
super Integer> - Correct: ✔✔lower bounded wildcard type The ability to use a parent reference variable to refer to a child object is an example of ___________ - Correct: ✔✔Polymorphism You should use a(n) ________ when you want to get values out of the structure - Correct: ✔✔extends wildcard For the below Test class which way of object creation is invalid? _____ class TestD. Test
C. Redesign of the user interface. D. Improving performance of the code. - Correct: ✔✔Redesign of the user interface Which statement is not true regarding an object in Java? ______ A. An object is instantiated from a class. B. An object must implement the Comparable interface. C. Static methods in a class cannot access the non-static instance parameters. D. An object variable contains a reference to an actual object. - Correct: ✔✔An object must implement the comparable interface According to Robert Martin identifiers in your code should exhibit all of the following except: ______ A. They should be camelback in format, always starting lower case.. B. They should be self-explanatory. C. They should exhibit meaningful distinctions. D. They should be pronounceable. - Correct: ✔✔They should be camelback in format, always starting lower case Which statement is not true about inheritance. ______ A. Parent class method method1 return type is Class A and child class of Parent class overrides the method method1 and can change the return type from Class A to Class B (B is the subclass of A)
B. A child class can use covariant return types in case of method overriding. C. Covariant return types can be used in case of method overloading. D. Method parameters ordering can change in overriding. - Correct: ✔✔Method parameters ordering can change in overriding Which statement(s) is true about subclasses? Pick one or more letters
A. We can override Constructors. B. We can override static methods. C. We can override abstract methods. D. We can overload abstract methods. - Correct: ✔✔C and D Which of the following is an incorrect statement regarding the use of generics and parameterized types in Java? ______ A. Generics provide type safety by shifting more type checking responsibilities to the compiler. B. Generics and parameterized types eliminate the need for downcasting when using Java Collections C. Once a generic class is defined you do not need to worry about using raw data types D. All of the above - Correct: ✔✔Once a generic class is defined you do not need to worry about using raw data types
A. public static void wildMethod( List<? super Integer> list) B. public static void wildMethod( List<? extends Integer> list) C. public static void wildMethod( List<? super Number> list) D. public static void wildMethod( List<? extends Number> list) - Correct: ✔✔A and B True or False: A superclass reference cannot be used to invoke a method or variable unique to the subclass. __________ - Correct: ✔✔True True or False: If you do not implement a default method one will always be created for you in any class. __________ - Correct: ✔✔False True or False: Static methods of a class can use the Type parameters of the class in which they are found. __________ - Correct: ✔✔False True or False: Every Collection class is generic. __________ - Correct: ✔✔True Which statement is true regarding an object in Java? _______ A. A class is instantiated from an object. B. The compareTo method is always inherited, although it may be overridden.
C. The equals method is always inherited, although it may be overridden.. D. An object variable contains a reference to an actual object. - Correct: ✔✔The equals method is always inherited, although it may be overridden If we had a scenario where we only want a method to work on an Double type but not a Integer type which of the following headers would work? (pick one or more) __________ A. public static void wildMethod( List<? super Double> list) B. public static void wildMethod( List<? extends Double> list) C. public static void wildMethod( List<? super Number> list) D. public static void wildMethod( List<? extends Number> list) - Correct: ✔✔A and B True or False: A default super is always included as the first statement in any constructor of a class. __________ - Correct: ✔✔True True or False: An interface can extend an interface. __________ - Correct: ✔✔False Given the following definitions, which assignments are legal? _____ class Box
D. Generic methods are methods that introduce their own type parameters - Correct: ✔✔Generic methods are methods that introduce their own type parameters When we talk about generics or a generic type what we are actually talking about? _________ A. A generalization B. A return type C. A parameterized type D. An object type - Correct: ✔✔A parameterized type Which of these types cannot be used to initiate a generic type?
A. Primitive Types B. Float class C. Integer class D. Collections - Correct: ✔✔Primitive Types Which of the following statements would be valid in Java. _________ A. List
D. List
A. public class SimpleGenericClass<> { ... } B. public class SimpleGenericClass
A. Implement inheritance. B. Refers to the ability of two or more objects belonging to different classes to respond to exactly the same message in different class- specific ways C. Simplifies code maintenance D. Refers to the ability of two or more objects belonging to different classes to respond to exactly the same message in different class- specific ways and simplifies code maintenance. - Correct: ✔✔Refers to the ability of two or more objects belonging to different classes to respond to exactly the same message in different class-specific ways and simplifies code maintenance List ______ Collection A. inherits. B. implements C. both A and B. D. Neither A nor B. - Correct: ✔✔inherits True or False: Generics can be applied to primitive types. - Correct: ✔✔False True or False: When the head pointer in a LinkedList in Java points to NULL, it signifies an empty list. - Correct: ✔✔True
Why do you get an error if you try to add an element to a List created from an array using asList? - Correct: ✔✔Because the array is fixed length (T/F) ArrayList is more efficient for insertions and deletions from the top of the List (i.e. 0TH position) than the LinkedList. - Correct: ✔✔False (T/F)Since arrays are covariant an array of supertype references is a supertype of an array of subtype references - Correct: ✔✔True (T/F) An overriding method of an abstract method in a subclass must have the same signature as the abstract method - Correct: ✔✔True (T/F) A lambda expression can modify local variables of the method inside of which the lambda expression is embedded. - Correct: ✔✔False (T/F) The following statement is valid:Queue