ITCS 1213 UNCC FINAL EXAM

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/107

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

108 Terms

1
New cards

Is it possible to create an array in Java where the first row has 5 elements, the second row has 6 elements and the third row has 2 elements?

yes

2
New cards

create a for loop to execute: Is it possible to create an array in Java where the first row has 5 elements, the second row has 6 elements and the third row has 2 elements?

double [] [] salaries = new double [NUM_STORES][];

array[0] = new double [5];

array[1] = new double [6];

array[2] = new double [2];

3
New cards

Write the statement to print the number of elements in a one-dimensional array.

for(i =0; i

4
New cards

What does Java initialize the elements of an array of references to?

null

5
New cards

What does Java initialize an array of ints to?

0

6
New cards

Is an array an object?

Yes

7
New cards

int [ ] numbers = new int[16] how many objects were created?

1, new was used once

8
New cards

Student [ ] roster = new Student[25] <- how many objects were created?

1, new was used once

9
New cards

Write the command to compile a source code file named Book.java

javac Book.java

10
New cards

Write the command to run a class file named Book.class

java Book

11
New cards

Where does the execution of a Java project begin?

public static void main(String [] args)

12
New cards

How many public classes can a Java class file contain?

1

13
New cards

Can you declare fields of a class inside a method?

No

14
New cards

What does private access for a field mean?

Only the current class will have access to the field or method.

15
New cards

What does public access for a field mean?

Any class can refer to the field or call the method.

16
New cards

What does protected access for a field mean?

Only the current class and sub classes (and sometimes also same-package classes) of this class will have access to the field or method.

17
New cards

What happens if you do not specify the access for a field?

It will set the access to package

18
New cards

Can a sub-class also be a super-class?

Yes, Java allows this

19
New cards

What is an abstract method?

It is a method that is declared, but contains no implementation

20
New cards

What is an abstract class?

Is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be sub classed.

21
New cards

Does a super class have to be abstract?

No

22
New cards

How many classes can a class directly inherit from?

1

23
New cards

How many interfaces can a class implement?

Multiple or unlimited

24
New cards

What can a Java interface contain?

Consists of modifiers, the keyword interface, the interface name, a comma-separated list of parent interfaces (if any), and the interface body

25
New cards

Can an interface be instantiated?

You can never instantiate an interface in java.

26
New cards

Does the is-a relationship apply to classes that implement an interface?

No

27
New cards

What is the difference between overloading a method and overriding a method?

Overloading: is the ability to create multiple methods of the same name with different implementations.

Overriding: is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

28
New cards

What class does every class indirectly inherit from?

Object class

29
New cards

What is a method every class has whether you write it or not?

object.equals() method

30
New cards

What causes a null-pointer exception?

is thrown when an application attempts to use an object reference, having the null value.

31
New cards

What is the purpose of the dot operator?

It allows one to invoke a method within an object when given a reference to the object

32
New cards

What is meant by encapsulation?

is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as as single unit.

33
New cards

What type of Exceptions require the programmer to acknowledge?

Checked Exceptions

34
New cards

What type of Exceptions do not require the programmer to write any additional code?

Unchecked or Run time Exceptions

35
New cards

Name three checked exceptions

SQLException

IOException

DataAccessException

ClassNotFoundException

InvocationTargetException

36
New cards

Name three RuntimeExceptions.

Also called unchecked examples,

NullPointerException

ArrayIndexOutOfBoundsException

ArithmeticException

IllegalArgumentException

37
New cards

What pre-written class is used to write data to a file?

Print Writer

38
New cards

What pre-written class is used to break a String into smaller Strings?

String Tokenizer

39
New cards

Write the code for opening a file named: accounts.txt for input.

String fileName = "C://clientdata.txt";

input = new Scanner(new File(fileName));

40
New cards

Use the following hierarchy to answer 40-43

public abstract class BankAccount

public class SavingsAccount extends BankAccount public class CheckingAccount extends BankAccount public class CheckingPlus extends CheckingAccount

Which of the following are valid declarations?

a) BankAccount bA = new BankAccount( ):

b) BankAccount bA = new SavingsAccount( );

c) BankAccount bA = new CheckingPlus( );

d) CheckingAccount bA = new CheckingPlus( );

e) SavingsAccount bA = new CheckingAccount( );

f) CheckingAccount bA = new CheckingPlus( );

g) ChekingPlus bA = new CheckingAccount( );

B, C, D, AND F

41
New cards

If BankAccount( ) class has an abstract method named withDrawFunds ( ) what do you know about the SavingAccount class and the method withDrawFunds( )?

That the savings account class will have a method called withdraw funds

42
New cards

If BankingAccount( ) has a protected method named depositFunds( ) can the CheckingAccount class override this method with a private method named depositFunds( )?

No because it has to be the same or less restrictive

43
New cards

What will happen if the BankAccount class does NOT have a default constructor written, the CheckingAccount does have a default constructor and main( ) tries to create an instance like this: CheckingAccount cA = new ChekingAccount( );

All fields in the default CheckingAccount will be set to null.

44
New cards

Is the call to the super's constructor always made?

Yes

45
New cards

If a subclass explicitly calls the constructor of the superclass, where must the call be made in the subclass constructor?

It will call the default if not specified

46
New cards

Can a subclass write methods that do not appear in the superclass?

Yes

47
New cards

Must a subclass override every method of its superclass?

No, it just has to override all of the abstract methods

48
New cards

T/F The finally block of a try/catch/finally only executes if the method throws an Exception

False, it always executes

49
New cards

What is meant by an Exception propagating up the call stack

An exception propagates from method to method, up the call stack, until it's caught. So if a() calls b(), which calls c(), which calls d(), and if d() throws an exception, the exception will propagate from d to c to b to a, unless one of these methods catches the exception.

50
New cards

When using the BlueJ debugging tools, what is the difference between the Step command and the StepInto command?

Step into will jump from class definition file to class definition file. Step stays in the class definition file.

51
New cards

What is a Java package?

is a namespace that organizes a set of related classes and interfaces

52
New cards

What is contained in a Java package?

Classes and Interfaces

53
New cards

Does the Java compiler compile source code to machine code?

No, It compiles source code to byte code

54
New cards

Why does a person who wants to run a Java program need a Java Virtual Machine installed on their computer?

Because java code is not a compiled language so it needs something to run it.

55
New cards

What is the purpose of the import statement?

in Java, it allows to refer to classes which are declared in other packages to be accessed without referring to the full package name.

56
New cards

Does using the import statement make your compiled class file larger?

No

57
New cards

T/F If a method throws an Exception and the Exception is caught in a catch block, the method continues executing the code after the catch block.

True

58
New cards

Write the class definition for a check-exception named: ImproperPriceException:

public class Myexception extends IOException{

59
New cards

Write the class definition for a RuntimeException named: ImproperPriceException:

public class My exception extends RuntimeException{

60
New cards

What are the 4 components (concepts) every object-oriented language must have?

Encapsulation, Data Abstraction,

Polymorphism and Inheritence

61
New cards

What is the return type of the compareTo( ) method?

integer 0,1

62
New cards

What is the parameter to the equals( ) method?

objects being compared

63
New cards

What are the parts of a method signature?

Name of the method and parameters

64
New cards

Can two methods in the same class definition file have the same signature?

No

65
New cards

What must a class do to implement an interface besides declaring that in the class heading?

Overide all methods

66
New cards

What method is used to retrieve the error message from an Exception

getMessage();

67
New cards

What is the access specifier for all methods in every Java interface?

public

68
New cards

In the following class heading, which is the subclass?

public class ClassA extends ClassB implements ClassC

ClassA

69
New cards

Any object that can be thown as an Exception must inherit from what class?

Throwable

70
New cards

What is the correct header for a method that will accept an array of ten integers as an argument?

public void printMe(int [10] in array))

71
New cards

If price has a value of 25, what is the value of discount after this statement? discount = price < 25? .10: .20;

.2

72
New cards

What does the term: polymorphism actually mean in English?

the condition of occurring in several different forms.

73
New cards

T/F: All static fields must be declared as final?

False

74
New cards

T/F: A constant must be given a value in the same statement in which it is declared.

True

75
New cards

T/F: The programmer must write a constructor method for each class he/she writes or the class will not compile.

False

76
New cards

Look at this method heading:

Date addDays(int innumber) What is the return type from this method?

object reference variable of a date object

77
New cards

Is the following an abstract method?

int addValue(float amount) { }

No

78
New cards

What is the name of the Java compiler?

Javac

79
New cards

What are the two categories of data types in Java?

primitive and reference

80
New cards

What numeric data type holds an exact value?

int

81
New cards

Can a field declared as type boolean hold a value of 1?

No

82
New cards

What primitive Java data type can hold the largest integer value?

long

83
New cards

What are the four levels of access for fields and methods in a class definition file?

public, protected, default, private

84
New cards

Which level of access gives access to other classes that are sub-classes?

protected

85
New cards

Which level of access gives access to any other class?

public

86
New cards

Which level of access restricts access to only methods in the same class file?

private

87
New cards

What is the keyword used to give access to other classes in the same package?

package

88
New cards

Why is public access a dangerous access that should be rarely used?

It breaks encapsulation and anyone can change values of fields

89
New cards

What is an interface comprised of in Java 7?

method heading

90
New cards

Can an interface have fields?

Yes

91
New cards

What is the access of all the methods in a Java interface?

public

92
New cards

Can an interface be instantiated?

No

93
New cards

Give two reasons for interfaces in the Java language.

To implement a list of methods and organization

94
New cards

How many interfaces can another class implement

As many as needed

95
New cards

What does it mean to implement a Java interface

Create a class that overrides all the methods

96
New cards

If a class extends an Employee class and implements a Comparable interface, what are the is-a relationships established?

The given class is a: is - a relationship

97
New cards

How many classes can a given class extend?

one

98
New cards

Name five Java pre-written interfaces

N/A

99
New cards

What are the two broad categories of Exceptions in Java?

Checked and Unchecked(Run Time)

100
New cards

What is the major difference between a checked exception and an unchecked exception?

Checked: is all those Exception which requires being catches and handled during compile time.

Unchecked: is those Exceptions whose handling is not verified during Compile time.