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

ITSC 1213 UNCC Practice Final Exam: Java Programming Exercises and Questions, Exams of Computer Programming

A comprehensive set of practice questions and exercises for the itsc 1213 uncc final exam, covering key concepts in java programming. the questions test understanding of exception handling, abstract classes, interfaces, inheritance, polymorphism, and array manipulation. it's a valuable resource for students preparing for the exam, reinforcing their knowledge through practical application.

Typology: Exams

2024/2025

Available from 05/10/2025

patrick-maina-2
patrick-maina-2 🇬🇧

296 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ITSC 1213 UNCC practice final exam
If the code inside a try block throws a FileNotFoundException and an IOException, which of the
following are correct ways of handling this (i.e. results in code that compiles)? (Select all that apply)
Having multiple catch block starting with IOException followed by an FileNotFoundException
Having one catch block that catches FileNotFoundException and declaring the method to throw an
IOException
Having one catch block that catches Exception
Having multiple catch block starting with FileNotFoundException followed by an IOException
Having one catch block that catches FileNotFoundException
Having one catch block that catches IOException ✔✔Having multiple catch block starting with
FileNotFoundException followed by an IOException
An abstract class can be _____________.
instantiated
all of the above
extended
without constructor ✔✔extended
You define a class, Shape, and create an object of Shape called triangle. You do not include a toString()
method in Shape. Would the following code compile and execute normally:
triangle.toString();
No. This code will cause a execution error, because you did not specifically inherit the Object class.
No. This code will produce a compile error, because you did not specifically inherit the Object class.
Yes. Because Java will recognize that the method is missing and will automatically generate the
toString() method for you.
Yes. Because Shape inherits the Java class, Object. Object includes a toString() method which is
automatically inherited by your class, Shape. ✔✔Yes. Because Shape inherits the Java class, Object.
Object includes a toString() method which is automatically inherited by your class, Shape.
An array can have several different types of data simultaneously.
pf3
pf4
pf5

Partial preview of the text

Download ITSC 1213 UNCC Practice Final Exam: Java Programming Exercises and Questions and more Exams Computer Programming in PDF only on Docsity!

ITSC 1213 UNCC practice final exam If the code inside a try block throws a FileNotFoundException and an IOException, which of the following are correct ways of handling this (i.e. results in code that compiles)? (Select all that apply) Having multiple catch block starting with IOException followed by an FileNotFoundException Having one catch block that catches FileNotFoundException and declaring the method to throw an IOException Having one catch block that catches Exception Having multiple catch block starting with FileNotFoundException followed by an IOException Having one catch block that catches FileNotFoundException Having one catch block that catches IOException ✔✔Having multiple catch block starting with FileNotFoundException followed by an IOException An abstract class can be _____________. instantiated all of the above extended without constructor ✔✔extended You define a class, Shape, and create an object of Shape called triangle. You do not include a toString() method in Shape. Would the following code compile and execute normally: triangle.toString(); No. This code will cause a execution error, because you did not specifically inherit the Object class. No. This code will produce a compile error, because you did not specifically inherit the Object class. Yes. Because Java will recognize that the method is missing and will automatically generate the toString() method for you. Yes. Because Shape inherits the Java class, Object. Object includes a toString() method which is automatically inherited by your class, Shape. ✔✔Yes. Because Shape inherits the Java class, Object. Object includes a toString() method which is automatically inherited by your class, Shape. An array can have several different types of data simultaneously.

false true ✔✔False Unit tests are statements that exercise some code and compare the computed result with the expected result. true false ✔✔true What does the following code do: File file = new File("sample.txt"); Scanner fileReader = new Scanner(file); while(fileReader.hasNext()) { String line = fileReader.nextLine(); System.out.println(line); } The code prints the file sample.txt to a socket The code prints the file sample.txt to the console The code prints the file sample.txt to the standard error The code copies the file sample.txt to another file ✔✔The code prints the file sample.txt to the console An array can hold multiple values of the same type of data. false true ✔✔true Your method has a try/catch block that handles 4 exceptions. The first catch block catches an exception. When will the code in the remaining catch blocks be executed? After the second catch block is done executing They will not be executed Unknowable without knowing the specific type of exception

Yes, 9 No, you cannot instantiate interface objects this way ✔✔No, you cannot instantiate interface objects this way Imagine you are planning a new java project but need help deciding if what you are writing should be a concrete class, abstract class, or interface. Three subclasses will eventually extend or implement what you are writing. Two core attributes are shared between the three sub-classes that need to be initialized and have getters and setters. At least one method will have the exact same implementation in all three subclasses. At least one method these subclasses inherit will need a completely different implementation in each subclass. You will not need to create objects of the superclass type. Should this be a concrete class, abstract class, or interface? Concrete class Abstract class Interface ✔✔Abstract class What will be the output of the following code? interface Contract { public String contract(int i); } public class Contractor implements Contract { public String contract(int i) { return "The project will be done in "+i+" months"; } } public class Main { public static void main(String[] args) { Contract c = new Contractor(); System.out.println(c.contract(3)); } } 3 The code will not compile

The project will be done in 3 months No, you cannot instantiate interface objects this way The code has nothing to print out ✔✔The project will be done in 3 months Say that you are writing a class Employee and wish to implement the Comparable interface. Then, Employee class must contain and implement the method int compareTo(Employee ). true false ✔✔true Given a document "employees.txt" that contains the following lines: Name,Dept,ID Manar,Sale, Sami,Engineering, Dalia,Production, David,Sale, Omar,Sale, Rama,Sale, and the following code that reads this file: ArrayList empData = new ArrayList(); fileScanner = new Scanner(new File("employees.txt")); fileScanner.nextLine(); while (fileScanner.hasNextLine()) { String line = fileScanner.nextLine(); String[] lineArray = line.split(","); if (lineArra[1] == "Sale" && lineArray[2] > 801) ) { empData.add(lineArray[0]); } } 3 1 0 2 ✔✔ 3 If you have a private method called calculateAverage() in Grade Class, how would you call this method on an object of Grade called myGrade?

B a = new A(); a.toDo() // call the code implemented in A no B, which of the following must be true? (Select all that apply) The superclass and subclass method signatures must be the same The toDo() method must be a member of the subclass: A The toDo() method must be a member in the superclass: B The superclass and subclass method return types must be the same. ✔✔The superclass and subclass method signatures must be the same The toDo() method must be a member of the subclass: A The toDo() method must be a member in the superclass: B The superclass and subclass method return types must be the same. (all of them) Which of the following is/are false about interfaces? (Select all that apply) a class can implement any number of interfaces they cannot contain fields can only contain abstract methods all fields are final and static ✔✔they cannot contain fields