COSC 1337 Final Review

¡Supera tus tareas y exámenes ahora con Quizwiz!

Assume that inside a class called Sky Consider this header: public Color getColor( ) What would that method be?

accessor

Which of the following is true of a subclass? It can have only one direct superclass It inherits the fields of the superclass All of these are true It inherits the methods of the superclass

all of these are true

When we open a file for reading and the file does not exist, what happens?

an exception is thrown

In a class, fields ... can only be basic data types or existing Java types (from existing classes) can be basic data types, existing Java types, or user-defined types (from user-defined classes) No answer text provided. can only be basic data types

can be basic data types, existing Java types, or user-defined types (from user-defined classes)

In Java, multiple inheritances is implemented using the concept of

interface

Which of the following is true of a private field in a class ... it can be accessed directly only from inside the class it can be accessed directly from any class

it can be accessed directly only from inside the class

Assume that the class Airplane has this method with the following method header: public String process2(char c) Which of the following is NOT true of process2? it is a class method all of these are true its return type of String it is an instance method

it is a class method

Which of the following is the correct Java package that contains classes for input and output operations?

java.io

Which of the following is NOT true of an accessor method? named getIV where IV is an instance variable name used to access field variables of a class from outside the class returns void typically take no parameter

returns void

When we open a file for writing ...

the contents of the file are deleted if any

A variable defined inside a try block is local to that block.

true

File contents can be converted to a stream.

true

Instance variables and methods can be accessed anywhere in the class.

true

Instance variables reflect the properties that all objects will have in common.

true

Method names should begin with a lowercase letter.

true

One of the advantages of inheritance is that we can write the common code only once and reuse it in multiple classes.

true

Some methods that throw an exception require try and catch blocks, while some do not.

true

The Stream interface includes functionality to perform aggregate sequential operations and parallel operations on a collection of elements.

true

The constructor for a class is required to have the same name as the class name.

true

Given these three classes ... What is the output of this code sequence: B b2 = new B(); b2.foo1();

A called B () called B version of foo1 called

Given these three classes ... What is the output of the following code: C c1 = new C();

A called B () called C called

The extends keyword applies to A class inheriting from another class A variable A method An expression

A class inheriting from another class

Given these two classes ... Which of the following is true of class B: All of these are true foo3 is overridden foo2 is overriden B inherits name and price from A

All of these are true

In a typical class, what is the general recommendation for access modifiers?

Instance variables are private and methods are public

What is the output of this code snippet: try{ Scanner file = new Scanner (new File ("data.txt")); String s = ""; while (file.hasNext ()) { s = file.nextLine(); } if (s.equals("A")) System.out.println("Nice finish");} catch (IOException ioe){System.out.println (ioe.getMessage ());} If the file data.txt contains the following: A B C A B A

Nice finish

If a class contains an abstract method, then

The class must be declared as abstract

What is the output of this code snippet: try {Scanner file = new Scanner( new File("data.txt")); int n = 0; while (file.hasNext()) {String s = file.nextLine(); if (s.equals("B")) n++; } System.out.println("The value of n is " + n); } catch (IOException ioe) {System.out.println(ioe.getMessage());} If the file data.txt contains the following: A B C A B A

The value of n is 2

Which of the following is responsible for initializing the instance variables of the class?

constructor

What is the output of this code snippet ... try { Stream<String> dataStream = Files.lines(Paths.get("data.txt"));long count = dataStream.filter( letter-> letter.charAt(0) == 'A').count(); System.out.println("count = " + count);} catch (InvalidPathException ipe) {System.out.println(ipe.getMessage()); } catch (IOException ioe) {System.out.println(ioe.getMessage()); } catch (SecurityException se) {System.out.println(se.getMessage()); } If the file data.txt contains the following: A B C A B A

count = 3

A Java class can directly inherit from two or more classes.

false

In Java, a class can only implement one interface.

false

Mutator methods typically take no parameter.

false

Not all classes inherit from the Object class.

false

Try/catch blocks can replace selection statements, thus saving CPIU time.

false

We can use the Path and Files classes to convert file contents to a scanner.

false

When coding a try and catch block, it is mandatory to code a finally block.

false

What is the keyword used for declaring a constant?

final


Conjuntos de estudio relacionados

Course 3 Week 2 Wireless protocols and WPA

View Set

Physics Test 1 Practice Problems

View Set

Infant and Child Development- Exam 2 Quiz Questions 5-9

View Set

Western Civilization II: Chapter 17

View Set

Chapter 7: Project Cost Management

View Set