CS 151 Previous Quiz Questions

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

We have Product class and we are going to create the OnlineCart class. Draw a class diagram that shows how you aggregate Product class in the OnlineCart class. Multiplicity are required and the relationships are unidirectional.

1 * OnlineCart <>--------- Product

Which one is true for this code? (Assume class Foo exists and has toString() method.) System.out.println(new Foo()); A) new Foo() is an anonymous object. B) new Foo() is an abstract class. C) new Foo() is a lambda expression. D) None is correct.

A

Which one is true for this code? public class Foo { private int age; public abstract void getName(); default int getAge() { return age; } } A) The code cannot be compiled B) It's an abstract class. C) It's a concrete (regular) class D) None is correct

A A regular class can't have abstract methods such as getName( ).

Pick all true statements about Java "static nested class". A) They have access to only static members of the outer class. B) They can have static and non-static members. C) The outer class has access to all members of them. D) None of the above

A & B

What do we get when we use polymorphism? (select all correct answers) A) Lower dependency B) Higher reusability C) Lower abstraction D) None of them

A & B

What do we get when we use polymorphism? (select all correct answers) A) Lower dependency B) Higher reusability C) Lower abstraction D) None of them

A & B Polymorphism increases abstraction.

Pick all that are class members in OOP? A. Instance variables B. Interface C. Methods D. None are correct

A & C

Pick all true statements about Architectural design patterns. A) They divide the whole software into pieces. B) They define what technologies the application should use. C) They define how the pieces should communicate with each other. D) None is correct.

A & C

Pick all true statements about Singleton pattern. A) This is a creational design pattern. B) It decreases coupling between classes. C) Only one instance of the class can exist. D) None is correct.

A & C A Singleton is a single class instantiation.

We know that class Y inherits class X and X has a public method called aMeth that is overridden in Y. (Choose all true statements.) A. To call aMeth of class X in class Y, we must use "super." keyword. B. To call aMeth of class Y in class Y, we must use "this." keyword. C. To call aMeth of class Y in class Y, we can use "this." keyword optionally. D. None of them are correct.

A & C ClassX is the superclass/parent and ClassY is the subclass/child. So, if we want Class X's aMeth, we need to specify with the "super." keyword. Since we are already in ClassY's class and it has aMeth, we don't need to specify it with the "this." keyword, though it would be recommended. Analogy: If you are holding a cup, you can refer to the cup as "this cup" and "the cup".

What is the definition of "design pattern"?

A proven advice to solve a class of similar problems

Pick all true statements about lambda expressions: A) It makes the code more readable. B) It has rich APIs and libraries. C) It has great support for parallel processing. D) None is correct.

A, B & C

Which one is class member in OOP? A. Instance variables B. Attributes C. Methods D. None of the above

A, B & C

Choose all true statements. A) A class tagged as final cannot be sub-classed (extended, or inherited). B) A method tagged as final cannot be overridden. C) An attribute tagged as final cannot be altered. D) None of them are correct.

A, B & C "final" is final

Pick all true statement in OOP. A. Paradigm is a method for modeling and representing of the entities and their interactions. B. In object-oriented paradigm, we model the entities of the real universe by "Objects". C. Behavior of an object is the set of the operations (or services) that object can do (or give). D. Identity of an object is the name we give to it.

A, B & C In Java terms, the "identity" is an internal name given by the JVM

Using inheritance (choose all true statements) A. increases complexity of the code. B. increases the dependencies. C. increases the cost of maintenance. D. increases the clarity of the code

A, B & C More stuff from the parent to watch out for = less clarity in code

Assume there is a functional interface called Multiplier. Pick all answers that is equivalent to the following code: Multiplier mul = new Multiplier ( ) { @Override public double multiply(double a, double b) { return a * b; } }; A) Multiplier mul = (double a, double b) -> return a * b; B) Multiplier mul = (a, b) -> return a * b; C) Multiplier mul = (a, b) -> a * b; D) None of them

A, B and C (all forms of lambda functions, with C being the most concise)

Pick all true statements when comparing JavaFX and Swing: A) JavaFX has richer libraries. B) Programming with JavaFX is faster. C) JavaFX code is more readable. D) JavaFX is not part of Java 8 or higher.

A, B, & C

Pick all true statements in OOP. A. Paradigm is a way for modeling and representing of the entities and their interaction B. In object-oriented paradigm, we model the entities of the real universe by "Objects" C. Behavior of an object is the set of the operations (or services) that object can do (or give). D. Identity of an object is the name we give to it.

A, B, & C The JVM gives the object its identity.

Pick all that we get from MVC architectural pattern. A) Separation of concern satisfaction B) Users don't have direct access to data C) Decreasing dependency D) Better testability

A, B, C & D

Pick all true statements: A. Using abstraction reduces the complexity of code. B. Only Java has abstraction. C. Abstraction can have multiple levels. D. Abstraction increases reusability of the code.

A, C & D Abstraction is one of the fundamental concepts of the Object-Oriented Paradigm, and all OOD languages use this paradigm.

Pick all that we get from multi-layer architectural pattern. A) Separation of concern satisfaction B) More efficient application C) Decreasing dependency D) Better testability

A, C, & D A multi-layer architectural pattern may make a more efficient application, but a multi-layer pattern isn't guaranteed to create a more efficient application. Efficiency refers to the algorithm's speed. The layers can be seen as different "packages" for the code, making testing and checking stuff easier.

What do we learn from LSP? Pick all true. A) The role of precondition in inheritance. B) Interfaces should not be too fat. C) Some inheritances are not polymorphic. D) The role of postcondition in inheritance.

A, C, & D We noted some of the inheritances are not polymorphic. Role of precondition and postcondition.

What are the four fundamental concepts of OOP?

A-PIE Abstraction Polymorphism Inheritance Encapsulation

What is the definition of abstraction?

Abstraction is the ability to separate interface from implementation (in varying levels).

What is the definition of "class" in OOP?

An abstraction of similar objects

What is "functional interface" in Java terminology?

An interface that has one and only one abstract method

What is the definition of API?

Application Programming Interface. An API of a class is something that can be seen by other classes

What do we learn from ISP? Pick all true. A) The role of precondition in inheritance. B) Interfaces should not be too fat. C) Some inheritances are not polymorphic. D) The role of postcondition in inheritance.

B ISP is all about trying to make interfaces slimmer.

Pick all true statements for a Java "abstract class". A) Abstract class can be instantiated. B) Abstract class can be used in a polymorphic relationship. C) If a child class B extends an abstract class A, it must implement all abstract methods of A. D) Child class B inherits all visible implemented methods of abstract class A.

B, C & D Only a concrete class can be instantiated. An abstract class can't be instantiated

Draw a UML class diagram for the following classes. Assume bidirectional relationship. The multiplicities of the relationship are required. Course -- CourseSection

Bidirectional aggregation Course <>------- CourseSection (1 to *) [a course has multiple course sections] CourseSection <>-------- Course (1 to 1) [a course section has one course]

In design phase, how can we identify the classes?

By the nouns in the functional spec

Which one is true for this code? (Assume class Foo exists and has toString() method.) (new Foo()).toString(); A) This statement won't be compiled. B) It calls the toString method of a lambda expression. C) It calls the toString method of an anonymous object. D) None is correct.

C

Pick the best answer: A. None is correct B. Problem statement describes how we should solve the problem. C. Theoretically, problem statement is a clear description of the problem. D. B and C are correct.

C B refers to a Technical spec

Which one is correct about functional spec? A. None of them are correct. B. It describes how to solve the problem. C. Basically, it describes the required features. D. B and C are correct.

C B refers to a Technical spec

Class A aggregates class B if ... A. class A contains class B in its import library. B. class B contains class A in its instance variables. C. class A contains class B in its instance variables. D. class B contains class A in its local variables.

C If something is in the format "ClassA ______ ClassB", then it means that ClassA does something with the stuff from ClassB

We know that class Y inherits class X and X has a public method called aMeth that is NOT overridden in Y. (Choose all true statements.) A) To call aMeth in class Y, we have to use "super." keyword. B) To call aMeth in class X, we have to use "this." keyword. C) To call aMeth in class Y, we can use "super." keyword optionally. D) None of them are correct.

C Since aMeth is not overridden in Y, aMeth in Y is the same as aMeth in X.

We know the hierarchy of exceptions from the parent to the grandchild is: Exception, IOException, FileNotFoundException If we want to catch all of them, what would be the best order of catches? A) IOException, Exception, FileNotFoundException B) FileNotFoundException, Exception, IOException C) FileNotFoundException, IOException, Exception D) None is correct

C Want to go from the more specific exceptions to the more generalized exceptions FileNotFoundException is more general than IOException, and IO Exception is more general than Exception

Assume we have the following classes: Customer, Product, CreditCard and we are going to create the Order class. Draw one class diagram that shows how you aggregate the above classes in the Order class. Multiplicity are required and the relationships are unidirectional.

Customer, Product, and CreditCard are all connected to Order. 1 1 Order <>--------- Customer 1 * <>--------- Product 1 1 <>--------- CreditCard

Which one is true for this code? Foo foo = new Foo(); System.out.println(foo); A) foo is an anonymous object B) foo is an abstract class C) foo is a lambda expression D) None is correct

D

Choose all true statements. A. A class tagged as final cannot be instantiated. B. A method tagged as final cannot be overloaded. C. An attribute tagged as final can't be altered. D. None of them are correct.

D A class tagged as final can be instantiated. A method tagged as final can be overloaded. An attribute tagged as final can't be altered.

Pick the best answer: A. Problem statement is usually written by client. B. Problem statement describes what the problem is. C. Theoretically, problem statement is a clear description of the problem. D. All are correct.

D The client wants something developed b/c they need to solve a problem

Pick all true statements about Singleton pattern. A. Separation of concern satisfaction (separating a computer program into distinct sections) B. Users don't have direct access to data C. Decreasing coupling (degree of interdependence between software modules) D. Better testability E. None

E Singleton pattern is used when we need one and only one instance of an object at runtime. There is nothing being separated, and the user has direct access to everything, including data.

An object is an entity that has 3 properties: state, behavior, and name. (TRUE/FALSE)

FALSE "Name" is the name that you the user gives to something in general (e.g. naming your dog). However, the correct property of an object is referred to as an "identity", referring to the identity given by the JVM and not the user

Superclass "is-a" subclass in OOD. (TRUE/FALSE)

FALSE A subclass "is-a" superclass in OOD, since a superclass is more general and a subclass is more specific

Aggregation is also known as "is-a" relationship. (TRUE/FALSE)

FALSE Aggregation is also known as "has-a" relationship.

Class A is dependent on class B if class B uses class A. (TRUE/FALSE)

FALSE Class A is dependent on class B if class A uses class B. Class A needs Class B in order to do something

In inheritance, the more general class is called subclass and the more specialized class is called superclass. (TRUE/FALSE)

FALSE In inheritance, the more general class is called superclass and the more specialized class is called subclass.

Choosing the algorithms is a design concern. (TRUE/FALSE)

FALSE It's an implementation concern. The programmers ultimately decide this

Choosing the programming language is the analysis concern. (TRUE/FALSE)

FALSE It's an implementation concern. The programmers ultimately decide this

The subclass inherits all members of superclass. (TRUE/FALSE)

FALSE Only the visible members of the superclass are inherited

Superclass and subclass can declare attributes with the same name and that's a good idea. (TRUE/FALSE)

FALSE Superclass and subclass CAN declare attributes with the same name, but that's a bad idea since you'll likely be confusing one class for the other.

State of an object is the collection of its methods. (TRUE/FALSE)

FALSE The state of an object is the collection of its attributes (aka variables)

To discover classes, we should look for verbs in the functional spec. (TRUE/FALSE)

FALSE To discover classes, we should instead look for the nouns in the functional spec (classes = "stuff")

To discover responsibilities, we should look for nouns in the functional spec. (TRUE/FALSE)

FALSE To discover responsibilities, we should instead look for the verb in the functional spec (responsibilities = all the actions we need to do)

A design pattern is a finished design that can be transformed directly into code.

False

An anonymous class can have constructor. (TRUE/FALSE)

False

An anonymous class can have static methods. (TRUE/FALSE)

False

An inner class can have main method. (TRUE/FALSE)

False

An inner class can have static members. (TRUE/FALSE)

False

An inner class has access to only public members of its outer class. (TRUE/FALSE)

False

In Java, a class and the interface that it implements have no relationship. (TRUE/FALSE)

False

In Java, a class can implement only one interface. (TRUE/FALSE)

False

In Java, an interface can implement another interface. (TRUE/FALSE)

False

Since Java 8, interfaces can have static methods provided that the method is final. (TRUE/FALSE)

False

Using abstract classes extensively is recommended because it increases the readability of the code. (TRUE/FALSE)

False

Using lambda expressions is not recommended because it increases the complexity of the code

False

When we have a primitive type wrapper like "Integer" as an instance variable of a class, it is called aggregation because "Integer" is a class. TRUE/FALSE

False "Integer" is already part of Java and thus it is not using any separate files. That means that we don't need to call aggregation or inheritance.

An anonymous class can have abstract methods. (TRUE/FALSE)

False Abstract methods should be used multiple times, but an anonymous class is only run exactly once.

An outer class had direct access to all public members of its inner class. TRUE/FALSE

False An inner class is like a local method, and thus other classes (including the outer class) don't have access to it.

ArrayList<Manager> is a subtype of ArrayList<Employee> if Manager class is the subtype of Employee class. (T/F)

False ArrayList<Manager> and ArrayList<Employee> are Java generics. There is no type-subtype between Java generics. Wildcards use type-subtype instead.

DIP and DI are the same principle. (T/F)

False DIP - Dependency Inversion Principle - principal - one of the SOLID principles that helps us design/rely on interface DI - Dependency Injection - a technique for designing code - injecting instantiation into a class

A design pattern is a finished design that can be transformed directly into code. (T/F)

False Design pattern is just a template.

Architectural design patterns consider a portion of the application.

False It considers all of the application

The following code will compile (T/F): List<Employee> [ ] listArr = new ArrayList<> [20];

False Java generics can't allow us to create an array of an ArrayList. List is an interface on the left side but ArrayList<> on the right is an implementation.

We can declare a Null type in Java. (T/F)

False Null type is in Java, but we can't declare it. Null is a default type, a lack of a value.

We use Java "transient" keyword for those attributes whose values should be converted into the stream of bits. (T/F)

False The goal of serialization is when we want to save an active object inside your application or you want to save somewhere else. The keyword we are looking for is "Serializable"

We should put generic methods in generic classes. (T/F)

False We should put generic methods in classes that are not generic.

It is bad design when "fault" and "failure" are very close to each other. (T/F)

False We want the failure to be very close to the fault so when we find a failure than we can more easily find and fix the fault.

A static nested class can have only static members. (TRUE/FALSE)

False e.g. main is a static class but it has various members, not just static members

The output of analysis phase is called ...

Functional spec Functional spec lays out all the requirements demanded by the client. It is written by business analysts and readable by the client and designers.

Why Java does not allow multiple-inheritance?

It increases the complexity of programming.

What does MVC stands for? Briefly explain each one.

Model-View-Controller - Model maintains data objects - View maintains UI objects - Controller handles user's interactions, applies business rules, manipulate data and UI, etc.

What is the definition of an object?

Objects are instance variables that store a piece of information; it has 3 properties: state/"instance variable", behavior/"method", and identity

Draw one UML class diagram that shows the relationship between all of the following classes. Address, Person, Student, Professor

Person <> -------- Address (1 to *, or 1 to 1) Person <|------- Student Person <|------- Professor Person is a more abstract class than Student and Professor, so Student and Professor both inherit from Person. Address can be aggregated to Student and Professor, but it is most efficient to aggregate only Person because Student and Professor are both within the Person class.

Aggregation is a special case of dependency. (TRUE/FALSE)

TRUE

An object is an entity that has 3 properties: state, behavior, and identity (TRUE/FALSE)

TRUE

Interface of a class is all members that can be seen from outside of a class. (TRUE/FALSE)

TRUE

Interface of a class is whatever can be seen outside of class

TRUE

The criteria for testing an application is its functional spec. (TRUE/FALSE)

TRUE

When we have primitive data types like "int" in the instance variables of a class, it is not called aggregation because they are not classes. (TRUE/FALSE)

TRUE

API and Interface of a class are the same thing. (TRUE/FALSE)

TRUE API = Application Programming Interface

Creating a mockup of the final software helps to understand the software better. (TRUE/FALSE)

TRUE Anything to add further clarity helps

Objects are the instances of their classes.(TRUE/FALSE)

TRUE Classes are abstractions of objects

Inheritance is an asymmetric relationship. (TRUE/FALSE)

TRUE If ClassA inherits from ClassB, this doesn't guarantee that ClassB inherits from ClassA, just as a parent doesn't inherit part of their child's DNA

Software development process is not a linear progression through some phases. (TRUE/FALSE)

TRUE Some phases of the SDLC require multiple rounds of review

Object-oriented design methodology can deal with change and complexity. (TRUE/FALSE)

TRUE That's why OOD languages such as Java have persisted over time

The output of the design phase is called...

Technical Spec

What is the difference between "UML Sequence Diagram" and "UML Class Diagram?"

The UML class diagram visualizes the different classes of a program and their relationship while the UML sequence diagram instead shows the interaction between objects. UML Class Diagram is a static diagram while UML Sequence Diagram is a dynamic diagram ( shows interaction between objects during runtime.)

What is the definition of "polymorphism" in OOP?

The ability of passing/assigning a child's object to the parent's reference

What is the definition of "behavior" of an object?

The set of services an object can do; also known as "method"

What is the definition of "state" of an object?

The state of an object is the set of values of attributes at any given moment

A Java interface cannot have instance variables. (TRUE/FALSE)

True

A static nested class can have its own class members. (TRUE/FALSE)

True

All members of Java interfaces will be automatically "public" by default. (TRUE/FALSE)

True

An inner class has access to all members of its outer class. (TRUE/FALSE)

True

Architectural design patterns are in fact the first level of abstraction.

True

Basically, when a value is not assigned to any variable, it's called anonymous. (TRUE/FALSE)

True

Detecting type violations at compile time is better than detecting it at runtime because the sooner we detect the error, the lower the cost. (T/F)

True

Functional interface is an interface that can be used as a type for lambda expression. (TRUE/FALSE)

True

Functional interface must have one and only one abstract method. (TRUE/FALSE)

True

Generic method is a method with one or more type variables. (T/F)

True

In Java Exception hierarchy, the subclasses of "Throwable" class are "Exception" and "Error" classes. (T/F)

True

In Java, a class can implement multiple interfaces.

True

In Java, an interface can extend another interface. (TRUE/FALSE)

True

JavaFX is a replacement for Java Swing for creating a graphical user interface. (TRUE/FALSE)

True

Node in JavaFX applications is a visual element like button. (TRUE/FALSE)

True

Polymorphism helps OOP to cope with change and complexity. (TRUE/FALSE)

True

Since Java 8, an interface can contain implemented methods provided that they use "default" keyword. (TRUE/FALSE)

True

The less dependency line in your UML class diagram, the better. (TRUE/FALSE)

True

The root of Java exception hierarchy is "Throwable" class.(T/F)

True

Using lambda expressions is recommended because it makes the code concise and more readable. (TRUE/FALSE)

True

We can create desktop and web applications by using JavaFX and run them on Android, iPhone, and iPad. (TRUE/FALSE)

True

When you use polymorphism in your code, you move the dependency from concrete classes to interfaces that are more abstract. (TRUE/FALSE)

True

In Java, A[ ] is a subtype of B[ ] if A is a subtype of B. (T/F)

True Arrays have type-subtype relationship. It's part of the Java definition.

To serialize the object A, not only object A but also all its entire dependents should implement "Serializable" interface. (T/F)

True Be sure to review serialization if you want to be a developer.

We can inject dependencies via constructors and methods. (T/F)

True Because we have arguments.

The set of "preconditions" and "postconditions" are contracts between the coder and the users of the code. (T/F)

True By "users" we are not talking about the end-users but rather the other developers. The terminology should be consistent among the coder and the users.

The goal of SOLID principles are to design flexible software that can cope with change and complexity. (T/F)

True Change and complexity are two of the biggest issues for software engineers. If the code doesn't have both, the code will die.

Concrete classes usually change more than abstract entities. (T/F)

True Concrete classes have more detail and have more code than abstract entities. The more code, the more possibilities for change.

The "inversion" in DIP means we need to invert the direction of dependency from concretion to abstraction. (T/F)

True Dependency to abstraction is better than dependency to concretion (concrete classes). DIP is totally focused on this concept.

Java generic type is class type. (T/F)

True Everything in Java should be a class.

If Student is subclass of Person, then the following code is valid (T/F): Person[ ] std = new Person[10]; std = new Student[30];

True If Student is a subclass of Person, then a Student array is a subtype of the Person array. Second line of code is fine because a Student is a Person. type: Person, subtype: Student

For any changes in the code, there are a chance that we introduce new bugs. (T/F)

True If you fix a bug, there is a chance that other bugs will come up. No one can claim that their code is bug-free (like how you can't say that something has disappeared within a closed environment in Physics).

In OOD terminology, mutator is the same as setter. (TRUE/FALSE)

True Mutate and setting do the same job of changing/adding something.

UML stands for?

Unified Modeling Language

What is the definition of "method-overriding"?

When a subclass re-implements an inherited method in a different way

Is there any problem in the following code? (Java 8 or higher) If no, just say No, if yes, briefly explain. public interface Foo { private int age; public abstract String getFooName(); default int getFooAge() { return age; } }

Yes An interface can have abstract methods. It can also have implemented methods (as long as the "default" keyword is used). The only issue is that we can't have a private attribute in an interface.

What are the 5 phases out of 7 phases into which we break up the software development process?

planning, analysis, design, implementation, testing The entire Software Development Process is: Planning, Analysis, Design, Implementation, Testing, Delivery, and Maintenance (PAD IT DM)


Conjuntos de estudio relacionados

SIS220 [Midterm: 1-31, Final: 33-79]

View Set

PRACTICE AND CLASS Ch.11 (Capital Budgeting)

View Set

CS303 Data Structures Final Study Guide

View Set

Chapter: Life Insurance Policy Provisions, Riders, and Options

View Set

California eFoodHandlers Test Answers

View Set