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

CPSC 2150 EXAM 1 QUESTIONS LATEST UPDATE 2024/2025 WITH 100% DETAILED VERIFIED ANSWERS, Exams of Business Administration

CPSC 2150 EXAM 1 QUESTIONS LATEST UPDATE 2024/2025 WITH 100% DETAILED VERIFIED ANSWERS

Typology: Exams

2024/2025

Available from 10/22/2024

Wanjiruesther
Wanjiruesther 🇰🇪

5

(2)

936 documents

1 / 10

Toggle sidebar

Related documents


Partial preview of the text

Download CPSC 2150 EXAM 1 QUESTIONS LATEST UPDATE 2024/2025 WITH 100% DETAILED VERIFIED ANSWERS and more Exams Business Administration in PDF only on Docsity!

CPSC 2150 EXAM 1 QUESTIONS

LATEST UPDATE 2024/

WITH 100% DETAILED VERIFIED

ANSWERS

Who is responsible for making sure that the precondition of a function is met? The client that calls the function Who is responsible for making sure that the post-condition of a function is met? The implementer of the function Is it a good practice to have each function start with an if statement that checks to make sure the preconditions are true? False True or False? The precondition automatically checks and enforces itself by checking the value of the parameter, and returning an error if the parameter is incorrect. False How does the concept of information hiding help keep our data secure? Making attributes privates and only allowing access through public method controls limits access to data. If data is changes, it must go through a method where there is control over accepted values How does the concept of Separation of Concerns make it easier for our program to adapt to change? It separates the program into modules. This allows specific parts of the program to easily found and revised. It also allows the user to to separate different programs into areas in which are important. Is is safe to assume the invariant of a class is true at the beginning of a private method?

No Is is safe to assume the invariant of a class is true after the constructor for the object has been completed? Yes Is is safe to assume the invariant of a class is true after a private method has finished? No Is is safe to assume the invariant of a class is true during the body of a public method? No Is is safe to assume the invariant of a class is true when the object has been declared, but not initialized? No Is is safe to assume the invariant of a class is true at the beginning of a public method? Yes Is is safe to assume the invariant of a class is true during execution of a private method? No Is is safe to assume the invariant of a class is true after a public method has finished? Yes Which of the following can be the declared data type (syntactically allowed by the compiler, not best practice) a. An interface type b. A class type c. A primitive type

An interface type A class type A primitive type Which of the following can be the dynamic type (syntactically allowed by the compiler, not best practice) a. An interface type b. A class type c. A primitive type A class type Can any type of public method be in a interface file? No Can public default methods be in a interface file? Yes Can public abstract methods be in a interface file? Yes Can any type of public variable be in a interface file? No Can any type of private variables be in a interface file? No Can public static final variables be in a interface file? Yes Can any type of private method be in a interface file? No

Can private default methods be in a interface file? No Can private abstract methods be in a interface file? No The part of the interface specification that specifies the high level concepts that every implementation should have some way of representing is _____________ The interface specification does not specify this The part of the interface specification that specifies what should be true after the constructor has finished is The initialization ensures clause The part of the interface specification that specifies the private data fields that every implementation must have is The defines clause Grouping related data and operations together Done with classes and objects Can keep data in sync Encapsulation How we control access to encapsulated data and operations Done by using visibility settings (private, public, package) Information Hiding Each module has it's own role and concerns Makes modules role specific Work together to solve a more complicated problem One place to make change Separation of Concerns What are examples of modules?

Objects and classes Component providers are _________ Ex. write a function Implementers Users of the components are _________ ex. write code that calls a function client The (implementer or client?) writes the function implementer The (implementer or client?) writes codes that calls the function client Characterizes the responsibility of the client that calls the operation Precondition (requires clause) Characterizes that responsibility of the code that implements that operation Post condition (ensures clause) Who's responsibility is it to ensure precondition is met? client (writes codes that calls the function) Are always true (kinda) and must always be enforced Usually refer to some property of a variable in a class Invariant Who defines the invariant? Implementer of the class Can be accessed only by instances of the same class Provide concrete implementation/representation

Private members Can be accessed by any object Provide abstract view (client-side) Public members Who are the postconditions and preconditions meant for? client Who is the invariant meant for? The implementer Represent interactions between the system and it's users (exists to create a connection not encapsulate data) ex. user interface, scanner object Boundary objects Are responsible for the actual flow of the program (handles interactions between boundary and entity objects) Makes sure events happen in a certain order ex. main Control object Place to specify a contract and it provides a separation of concerns between class uses and implementer Interface What visibility can interfaces have? Public and package visible Can constructors be in a interface? No

Declare a class that implements that interface... Employee - class Salaried - interface class Employee implements Salaried { ... } How to define interface methods in class? return type - void function name - setSalary parameter - BigDecimal public void setSalary (BigDecimal d) { ... } Can interfaces be instantiated? No, don't have constructors ex. interface is Salaried Salaried payee = new Salaried(); created a compile time error Set at compile time declared type set at run time (by new) Dynamic type Sates what will be true after initialization (after constructor) Initialization ensures States what allows us to define some concepts for specification allows to hint at private variables must be generic and abstract

Defines clause States any other constraints needed to add in Similar to invariants Constraints clause Allows to ties concepts specified in the interface to the private data in the implementation Do reveal information Correspondences A method that is absolutely necessary for the object to be useful Primary operation A method that isn't necessary, but is helpful secondary operation The extends relation may hold between: Two interfaces or two classes True or False? Constructors are inherited if using extends False True or False? Static methods are inherited using extends True True or false? You can instantiate a abstract class False 8 primitive types? boolean, byte, short, int, long, float, double, char A grouping of classes/ hierarchial Package Variable that only one copy belongs to the class and can be accessed via the class name

static variables Why use static? only want to expose data that is same for every instance of class method than can be called using class name, and not declaring a object only have access to static data members, not instance members can only call methods that are static static methods Does the invariant go in the class or interface? Class Does the correspondence go in the class or interface? Class Does initialization ensures go in the class or interface? Interface Does the defines clause go in the class or interface? Interface Does the constraints clause go in the class or interface? Interface Does the preconditions and postconditions go in the interface or class? Interface Grid contains only blank characters and is MAX_SIZE x MAX_SIZE or smaller initialization ensures, defines, constraints, invariant or correspondence? Initialization ensures

number_of_rows: Z number_of_columns: Z initialization ensures, defines, constraints, invariant or correspondence? Defines clause 0 < number_of_rows <= MAX_SIZE 0 < number_of_cols <= MAX_SIZE initialization ensures, defines, constraints, invariant or correspondence? Constraints clause (similar to invariant but uses variables from defines and it located in interface) 0 < numRow <= MAX_SIZE 0 < numCol <= MAX_SIZE initialization ensures, defines, constraints, invariant or correspondence? Invariant (similar to constraints but uses private variable names from class) number_of_rows = numRow number_of_columns = numCol this = myGrid[0...numRow - 1][0...numCol-1] initialization ensures, defines, constraints, invariant or correspondence? Correspondence (connects defines variables to private variables in class)