Object Oriented Programming - Exam 1

Ace your homework & exams now with Quizwiz!

C. Three

1. Operators are special symbols that perform specific operations on up to how many operands? a. One b. Two c. Three d. Four e. None

A. True

A class can have multiple constructors. a. True b. False

D. Class, interface

A method in object oriented programming can return primitive data types, __________, or __________. a. Project, package b. Function, method c. Constructor, exception d. Class, interface e. Code, return

A. Expression

A(n) ________ comprises variables, operators, and method invocations. a. Expression b. Statement c. Abstract class d. Class e. Interface

C. Declaration statement

A(n) ________ declares a variable. a. Expression b. Expression statement c. Declaration statement d. Class e. Interface

B. Expression statement

A(n) ________ forms a complete unit of execution to include a terminating semicolon. a. Expression b. Expression statement c. Abstract class d. Class e. Interface

B. False

Access level modifiers do not define how other classes can reference a field or invoke a method. a. True b. False

A. True

An expression statement forms a complete unit of execution with a terminating semicolon. The following code is a correct example of an expression statement: Game game = new Game(); a. True b. False

A. A secondary path of execution when an "if" clause evaluates to false

An if/else provides what? a. A secondary path of execution when an "if" clause evaluates to false b. Nothing c. Two conditions to be evaluated for a true result d. Two conditions to be evaluated for a false result

A. True

Based on best practices and how the Java API Library is implemented a class should start with a capital letter (i.e. Dog versus dog). a. True b. False

D. Static

Class variables are _________. a. Non-static b. Final c. Local d. Static

B. False

Constructors MUST have a return type. a. True b. False

A. fields B. local C. Parameters

Define the following: a. ______ : member variables in a class b. ______: variables in a method or block of code c. ______: variables in method declaration

A. Yes

Does the following code include all required components for a class declaration? class NewClass { } a. Yes b. No, it's missing the fields and methods c. No, the access modifier is not required d. No, it's missing the return type e. No, it's missing the parentheses and parameter list

A. Yes

Does the following code include all required components for a method declaration? void thisMethod() { } a. Yes b. No, it's missing the access modifier c. No, it's missing the return type d. No, it's missing the parameter list e. No it's missing the argument list

D. Public methods are written to interact with the private fields

Encapsulation of class fields hides implementation details. How is encapsulation used to access fields of classes? a. Private methods are written to interact with the private fields b. Public methods are written to interact with the public fields c. Private methods are written to interact with the public fields d. Public methods are written to interact with the private fields e. None of the above, encapsulation is not a real topic in object oriented programming

A. True

For each case label in a switch decision-making statement the break is not required but are necessary to prevent statements in switch blocks from falling through. a. True b. False

B. Access level modifier

Given the class definition public class KeyTerminology{} what is "public" called? a. Membership level b. Access level modifier c. Data type of class d. Not relevant

B. False

Given the following class and interface definitions (location does not matter): static class Parent {} static class Child extends Parent implements MyInterface {} interface MyInterface {} public static void main(String[] args) { Parent obj1 = new Parent(); Parent obj2 = new Child(); boolean result = (obj1 instanceof Child); } What is the value of result? a. True b. False

A. true

Given the following class and interface definitions (location does not matter): static class Parent {} static class Child extends Parent implements MyInterface {} interface MyInterface {} public static void main(String[] args) { Parent obj1 = new Parent(); Parent obj2 = new Child(); boolean result = (obj1 instanceof Parent); } What is the value of result? a. True b. False

A. True

Given the following class and interface definitions (location does not matter): static class Parent {} static class Child extends Parent implements MyInterface {} interface MyInterface {} public static void main(String[] args) { Parent obj1 = new Parent(); Parent obj2 = new Child(); boolean result = (obj2 instanceof MyInterface); } What is the value of result? a. True b. False

A. True

Given the following class and interface definitions (location does not matter): static class Parent {} static class Child extends Parent implements MyInterface {} interface MyInterface {} public static void main(String[] args) { Parent obj1 = new Parent(); Parent obj2 = new Child(); boolean result = (obj2 instanceof Parent); } What is the value of result? a. True b. False

C. You are not old enough to purchase alcohol

Given the source code below, what would be the output to the console? int age = 18; if(age >= 21) System.out.println("You are old enough to purchase alcohol"); else System.out.println("You are not old enough to purchase alcohol"); a. You are old enough to purchase alcohol and You are not old enough to purchase alcohol b. You are old enough to purchase alcohol c. You are not old enough to purchase alcohol d. Nothing

D. Sequentially

How are statements in a source code file normally executed? a. Randomly b. Conditionally c. In reverse order d. Sequentially

B. unlimited

How many subclasses can a superclass have? a. 3 b. unlimited c. 2 d. 1

B. One

How many superclasses can a subclass extend when using inheritance in object-oriented programming using the Java programming language? a. Zero b. One c. Two d. Three e. Unlimited

A. 1

How many superclasses can a subclass have? a. 1 b. 2 c. 3 d. unlimited

C. It no longer exists

If a class explicitly declares a constructor that takes 0...n parameters when instantiated what happens to the default constructor of the class? a. It still exists and can be used to create instances of the class b. It is automatically created by the Java compiler c. It no longer exists d. All of the above e. None of the above

B. Control jumps to the end of the if statement

If the condition being evaluated in the source code below evaluates false, what happens? if(age >= 18) System.out.println("You are old enough to vote! Please register to vote, elections are this year!"); a. Nothing b. Control jumps to the end of the if statement c. the System.out.println() will be executed providing output to the console d. Variable age will be set to 0

A. varargs

If there are an unknown number of parameters being passed to a method a software developer can use a construct called __________. a. varargs b. an array c. an ArrayList d. a 2-d array e. None of the above

D. if/else if/else

If you need to evaluate more than one condition which decision-making statement is the best? a. while b. if c. if/else d. if/else if/else

B. No

In an if/else if/else, is the final else leg REQUIRED? a. Yes b. No

B. No

In an if/else if/else, once a condition is satisfied, are the remaining conditions evaluated? a. Yes b. No c. It depends d. Maybe

D. Member Variables

In object oriented programming how is state represented? a. Functions b. Methods c. Global variables d. Member Variables

C. Inside of another class

In object oriented programming where are inner classes defined? a. This isn't allowable b. Outside another class in a different file c. Inside of another class d. Outside another class but in the same file

E. Class

In object-oriented terms what is used as a blueprint to model a real-world object? a. Method b. State c. Behavior d. Constant e. Class

B. False

In the final case label of a switch decision-making statement, the break is still required and necessary. a. True b. False

B. Constructor

In the following statement, Dog puppy = new Dog();, what is "Dog()" called? a. Maker b. Constructor c. Creator d. malloc

A. True

Information hiding is accomplished via encapsulation a. True b. False

B. Non-static

Instance variables are __________. a. Local b. Non-static c. Static d. Final

A. True

Instance variables are unique to each instance of a class. a. True b. False

D. Temporary

Local variables store a __________ state. a. Permanent b. Static c. Instance d. Temporary e. None of the above

B. False

Local variables, like instance variables, must have an access modifier assigned. a. True b. False

A. Superclass, subclass

Object-oriented programming allows for inheritance so commonly used state and behavior can be reused. The class that is inherited from is the __________ and the new class is the __________. a. Superclass, subclass b. Subclass, superclass c. Interface, subclass d. Class, package e. Extends, implements

B. False

Operators do NOT have precedence rules. a. True b. False

B. A method or constructor is called

Parameters are different than arguments because arguments are used when __________. a. A method or constructor is defined b. A method or constructor is called c. A class is defined d. An interface is defined e. An abstract class is defined

A. A method or constructor is defined

Parameters are different than arguments because parameters are used when __________. a. A method or constructor is defined b. A method or constructor is called c. A class is defined d. An interface is defined e. An abstract class is defined

A. Defining a method

Parameters are used when? a. Defining a method b. Anytime c. Calling a method d. Defining a class member variables

C. State and behavior

Real world objects share which two characteristics? a. Inheritance and polymorphism b. Classes and interfaces c. State and behavior d. Times and dates

B. Non-static

Regarding classes, instance variables are __________. a. Static b. Non-static c. Both A and B d. None of the above

D. The second operand/expression is evaluated if needed

Regarding conditional operators (i.e. &&, ||) what does "short circuiting" behavior mean? a. Both operands/expressions are evaluated b. Only the second operand/expression is evaluated c. Only the first operand/expression is evaluated d. The second operand/expression is evaluated if needed e. None of the operands/expressions are evaluated

B. Relative needs to be combined with another path to access the file

Regarding file pathing there are two options, absolute and relative. Which of the following statements is true? a. Absolute never includes the root element and the complete directory list required to access the file b. Relative needs to be combined with another path to access the file c. Absolute needs to be combined with another path to access the file d. Relative always includes the root element and the complete directory list required to access the file e. There is no difference

1. Superclass 2. Subclass

Regarding inheritance the existing class is called ____1____ and the new class is called ____2____.

A. False

Regarding object-oriented programming, declaration means that a variable name is associated with an object type and creates an object of that type. a. True b. False

A. True

Regarding object-oriented programming, when an object is instantiated the keyword new is used, memory is allocated, and a reference to that memory is returned. a. True b. False

E. ++

Regarding operator precedence which of the following would be evaluated first? a. = b. * c. + d. instanceof e. ++

A. & C.

The + (plus sign) has two purposes in the Java programming languages, select the two that are correct. a. Addition b. Modulus c. Concatenation d. Division e. Subtraction f. Multiplication

D. The current object

The keyword this is used to reference __________. a. The inheritance b. The interface c. The subclass d. The current object e. The class's destructor

A. If/else

The ternary operator takes three operands and uses the (?:) notation. What control structure does the ternary operator mimic? a. If/else b. While loop c. Switch d. For loop e. Do/while loop

A. 1

Unary operators use how many operands? a. 1 b. 2 c. Unlimited d. 3

E. None of the above

Variable naming has rules associated with it. Which of the following is true? a. They can start with a number b. They can start with any special character c. They can include white space d. All of the above e. None of the above

D. Method overloading

What allows for methods to have the same name but different method signatures in object oriented programming? a. Class overriding b. Method overriding c. Class overloading d. Method overloading e. Shadowing

D. Method name and method parameter list

What are the components of a method declaration that comprise the method signature? a. Method return type and method name b. Method return type and method parameter list c. Method return type, method name, and method parameter list d. Method name and method parameter list e. All of the above

A, B, D, E

What are the required components of a method declaration? a. open/class curly braces b. return type c. access modifier d. method name e. open/close parenthesis e. static

A, C, F

What are the three components to declare a variable? a. data type b. final c. access modifier d. return type e. static f. variable name

B. implementing an interface

What behavior is the following code implementing? public class DogTwo implements IDog {} a. interfacing and implementation b. implementing an interface c. extending a subclass d. extending a superclass

D. Parameter list

What differentiates methods with the same name in a class? a. Return type b. Access modifier c. Argument list d. Parameter list e. None of the above, this is not permitted

E. Tests if the object is an instance of a class, subclass, or implements an interface

What does the instanceof operator do? a. Tests if the compared operands are equal b. Tests if the compared operands are identical c. Tests if the expression is true d. Tests if the expression is false e. Tests if the object is an instance of a class, subclass, or implements an interface

A. They cannot be modified

What does the keyword final indicated regarding methods or field members of a class? a. They cannot be modified b. They are public c. They are private d. They are modifiable e. None of the above

B. if/else if/else stop evaluating when it finds a true condition

What is a key difference between an if/else if/else and a switch control flow statement? a. switches stop evaluating when it finds a true condition b. if/else if/else stop evaluating when it finds a true condition c. Both stop evaluating when it finds a true condition d. if/else if/else continues evaluating after it finds a true condition e. None of the above, there is no difference

C, D, & E

What is the absolute minimum components to declare a class? a. open/close parenthesis b. access modifier c. key word "class" d. a name for the class e. open/close curly braces

D. class body

What is the area in a class called that is surrounded by open/close curly braces? a. struct b. method body c. class definition d. class body

D. switch block

What is the body of the switch decision-making statement called? a. case labels b. case block c. options block d. switch block

A. println() includes a line break, .print() does not

What is the difference between System.out.println() and System.out.print()? a. println() includes a line break, .print() does not b. print() includes a line break, .println() does not c. Nothing, they do the same thin

A. Unlimited

What is the maximum number of interfaces a class can implement? a. unlimited b. 1 c. 10 d. 2

B. 0

What is the minimum number of interfaces a class can implement? a. 1 b. 0 c. unlimited d. 2

C. if

What is the most basic of all control flow statements? a. switch b. do/while c. if d. if/else

C. Serve as the blueprint of how objects will be created

What is the purpose of a class in object oriented programming? a. To create a data structure for functions b. To create an interface for implementation c. Serve as the blueprint of how objects will be created d. To create a data structure for variables

A. To break up the flow of execution

What is the purpose of control flow statements? a. To break up the flow of execution b. To ensure sequential execution c. To ensure execution from bottom to top d. To ensure execution from top to bottom

C. To allow programs to run with a break up of execution flow

What is the purpose of control flow statements? a. To allow programs to run sequentially b. To allow programs to run line by line from top to bottom c. To allow programs to run with a break up of execution flow d. All of the above e. None of the above

D. namespace for organizing classes and interfaces in a logical manner

What is the purpose of packages in Java as an object oriented programming language? a. to include into the Java API b. namespace for organizing classes and interfaces in a illogical manner c. make it difficult to manage software in large projects d. namespace for organizing classes and interfaces in a logical manner

D. & B.

What is true about the ternary operator? Select all that apply a. uses two operands b. uses three operands c. uses one operand d. shorthand for an if-else statement e. must have its result assigned to a variable on the left of an = (equal sign)

B. Final

What keyword is used with a static variable to ensure its value cannot be changed? a. private b. final c. void d. protected

B. Inheritance

What type of implementation behavior is the following class definition doing? public class SubclassDog extends Dog{} a. Interface b. Inheritance c. Extending d. Implemenation

B. Interface

What type of object is the following code defining? public interface IDog {} a. inhertiance b. interface c. extending d. class

B. extends

When creating a subclass from a superclass what key word must precede the existing superclass? a. inherits b. extends c. implements d. uses

B. False

When defining a class, member variables are included within the class's open/close curly braces (i.e. {}) and methods are defined outside of the open/close curly braces. a. True b. False

E. A, B, or C

When does a method return to the code that invoked it? a. Completes all the statements in the method b. Reaches a return statement c. Throws an exception d. A or B e. A, B, or C

B. this

When having to programmatically differentiate a parameter having the same name as a field of a class what keyword can resolve this issue with the compiler when setting the field value equal to the argument value passed into the method? a. keyword b. this c. parameter d. argument e. in

D. Shadowing

When method parameters have the same name as class fields this is called __________. a. Repetition b. Duplication c. Same name d. Shadowing e. Confusion

C. int data;

When naming variables, which of the following IS valid? a. int 2to4; b. int #data; c. int data; d. void data;

D. parameter list

When overloading methods, what distinguishes each method so that it is unique? a. access modifier b. return type c. argument list d. parameter list

A. State, behavior

When using inheritance what does the new class inherit when it is derived from another class? a. State, behavior b. Object, class c. Inheritance, interface d. Function, method e. Project, package

C. & D.

Which of the following are ways to output to the console during runtime? Select all that apply. a. printf() b. fprintf() c. System.out.println() d. System.out.print()

D. Sequential statements

Which of the following is NOT one of the three types of control flow statements? a. Branching statements b. Looping statements c. Decision-making statements d. Sequential statements

A. Unlimited

Which of the following is NOT the number of operands an operator can perform specific operations on? a. Unlimited b. 2 c. 3 d. 1

D. Dog puppy = new Dog();

Which of the following is the correct code for instantiating an instance of class Dog? a. Dog puppy = Dog; b. Dog puppy; c. Dog puppy = Dog(); d. Dog puppy = new Dog();

C. puppy

Which part of the following statement is the instance or the created object? Dog puppy = new Dog(); a. Dog(); b. new c. puppy d. Dog

B. False

You MUST write a constructor for every class created. a. True b. False

B. an operator

instanceof is __________. a. a method b. an operator c. a function d. None of the options are correct


Related study sets

organs of the digestive system: matching

View Set

Principles of Marketing Final Exam Study Guide

View Set

Pre Calculus: Trigonometric functions

View Set

Legal and Ethical Environment (test 2)

View Set

Bones and Muscles of Head and Neck

View Set