Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSC 300 Exam 1 Study Guide and Final Exam: Java Concepts and Programming, Exams of Computer Science

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

2024/2025

Available from 12/22/2024

Martin-Ray-1
Martin-Ray-1 🇺🇸

5

(8)

6.1K documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC 300 Exam 1 Study Guide and CSC
300 Final Exam
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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download CSC 300 Exam 1 Study Guide and Final Exam: Java Concepts and Programming and more Exams Computer Science in PDF only on Docsity!

CSC 300 Exam 1 Study Guide and CSC

300 Final Exam

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: ___________

- 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 used

List < 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 {...} A. Class T extends B. B. B is a bounded parameterized type restricted to be of type T which is of type A or a subclass of A. C. T is a bounded parameterized type restricted to be of type A or a child of A. D. T is a bounded parameterized type restricted to be of type A or a parent of A. - Correct: ✔✔T is a bounded parameterized type restricted to be of type A or a child of A

Given the following definitions, which assignments are legal?


class Box{}class SuperBox extends Box{} I. Box b = new SuperBox(); II. Box b = new Box(); III Box b = new SuperBox(); - Correct: ✔✔I and II True or False: An abstract class must only have abstract methods. ___________ - Correct: ✔✔False True or False: It is not possible to create a generic array. ___________ - Correct: ✔✔True True or False: Every subclass must have a call to a super in the first line of each constructor or a default super constructor will be inserted. ___________ - Correct: ✔✔True True or False: A generic method cannot have the same method name as a non-generic method. ___________ - Correct: ✔✔False True or False: An interface with a single abstract method is called a functional interface. ___________ - Correct: ✔✔True

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: ___________

- 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 Test { } A. Test t1 = new Test(); B. Test t2 = new Test(); C. Test t3 = new Test();

D. Test t4 = new Test(); - Correct: ✔✔Test t1 = new Test(); The following statement is false because: ___________ List myL = new ArrayList(); A. Generic types are covariant B. Generic types are not covariant C. An interface variable can't refer to an actual class object. D. Number is an abstract class - Correct: ✔✔Generic types are not covariant Based on the class definition below, what can be inferred about the following class B: ___________ public class B {...} A. Class T extends B. B. B is a bounded parameterized type restricted to be of type T which is of type A or a subclass of A. C. T is a bounded parameterized type restricted to be of type A or a child of A. D. T is a bounded parameterized type restricted to be of type A or a parent of A. - Correct: ✔✔T is bounded parameterized type restricted to be of type A or a parent of A

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{}class SuperBox extends 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 aList = new List(); B. List aList = new ArrayList(); C. List aList = new List();

D. List aList = new ArrayList(); - Correct: ✔✔List aList = new ArrayList(); Which of the following is 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 down casts when using Java Collections C. When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes D. All of the mentioned - Correct: ✔✔When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple class How would we declare a generic class that accepts any object?


A. public class SimpleGenericClass<> { ... } B. public class SimpleGenericClass { ... } C. public class SimpleGenericClass { ... } D. public class SimpleGenericClass<?> { ... } - Correct: ✔✔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 aList = new ArrayList(); - Correct: ✔✔False (T/F) The following statement is valid: LinkedList aList = new LinkedList(); - Correct: ✔✔False