CS203 Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If you want your condition to depend upon two conditions BOTH being True, what is the proper notation to put between the two Boolean statements?

&& Correct! & 2& ||

What is a doubly linked circular list?

-Last node successor points to the head node -Head node predecessor points to last node

What is a singly linked circular list?

-last node next field points to the head of the list -No special case at ends of list -next() operation on last node returns first node -previous() operation on first node returns last node

What are two limitations of arrays?

-the size of arrays are fixed -inserting a new element in the array is expensive

What will be the output of the following code snippet? public class Main { public static void main(String[] args) { for (int i = 0; i < 5; i++) { if (i == 2) continue; System.out.print(i + " "); } } }

0 1 infinite loop (0 1 2 2 2 2 2.......) 0 1 3 4 Correct! 0 1 2 3 4

What is the output of the following code? public static void main(String args[]) { int x = 10; for (int y=0; y<5; y++, x--) System.out.print(" " + x); }

0 1 2 3 4 9 8 7 6 5 10 9 8 7 6 Correct! Compilation Error

What is the output of the following code snippet? public class Example { public static void main(String[] args) { int i = 0; while (i < 5) { System.out.print(i + " "); i += 2; } } }

0 2 4 6 2 4 6 2 4 0 2 4 Correct!

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int i = 0; while (i++ < 5) { System.out.print(i + " "); } } }

1 2 3 4 5 Correct! 0 1 2 3 4 2 3 4 5 6 0 1 2 3 4 5

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int x = 5; float y = x / 2; System.out.println(y); } }

2.0 Correct! 2 3 2.5

What is the output of the following code snippet? public class Example {public static void main(String[] args) { int x = 5; int y = 2; System.out.println(x / y); } }

2.5 2 Correct! Error 2.0

What is the output of the following code snippet? public static void main(String[] args) { double price = 49.99; int discount = 20; double discountedPrice = price - discount; System.out.printf("%.2f%n",discountedPrice); }

29.99 Correct! 29 30.00 49.79

What is the result of the following code snippet? int num = 6.45;

7 Error Correct! 6.45 6

What is the output of the following code? //Assume the following is located in A.java file public class A { void display() { System.out.println("A"); } } //Assume the following is located in B.java file public class B extends A { void display() { System.out.println("B"); } } //Assume the following is located in Main.java file public class Main { public static void main(String[] args) { A obj = new B(); obj.display(); } }

A B B Correct! B A A

Which statement is not True about the Classes?

A class should represent a single concept The public interface of a class should be cohesive All classes must include a main() method Correct! In order to identify a class, we should look for the nouns

If the Class B inherits from Class A, which of the following cannot be said:

A is a super-class of B B is a sub-class of A B has access to private methods of A Correct! B has access to protected methods of A

What is the expected output of the following code? public class Main { public static void main(String[] args) { int x = 10; System.out.println(x++); System.out.println(++x); } }

A) 11 23 B) 10 12 Correct! C) 10 11 D) 11 12

Which of the following statements is not True?

A) A reference is the location in memory that an object resides B) There can be multiple variables referencing same object C) The value of an object variable is a reference D) References are mutable Correct!

Which statement is not True about the JAVA Variables?

A) A static variable shared by all instances of the class B) A global variable doesn't belong to a specific method C) An instance variable shared by all instances of the class Correct! D) A static variable belongs to the class

Which of the following is true about arrays in Java?

A) Arrays can only hold primitive data types. B) Arrays can be resized dynamically. C) Arrays can hold elements of different data types. D) Arrays have a fixed size once created. Correct!

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int number = 10; System.out.println("Before calling modifyValue method: " + number); modifyValue(number); System.out.println("After calling modifyValue method: " + number); } public static void modifyValue(int value) { value = 20; System.out.println("Inside modifyValue method: " + value); } }

A) Before calling modifyValue method: 10 Inside modifyValue method: 20 After calling modifyValue method: 20 B) Before calling modifyValue method: 10 Inside modifyValue method: 20 After calling modifyValue method: 10 Correct! C) Before calling modifyValue method: 20 Inside modifyValue method: 20 After calling modifyValue method: 20 DBefore calling modifyValue method: 10 Inside modifyValue method: 10 After calling modifyValue method: 10

Which of the following statement is not True about JAVA constructors?

A) Constructors can be private. B) Constructors don't have a return type. C) Constructors can't be inherited. Correct! D) Constructors are used to create objects of a class.

Which of the following statements about Object-Oriented Programming (OOP) concepts is correct?

A) Inheritance allows a class to acquire the properties and methods of another class. Correct! B) Polymorphism can be implemented without inheritance C) Abstraction is the process of creating multiple instances of a class. D) Encapsulation refers to the process of creating arraylist

Which of the following is true about the private access modifier?

A) It allows access to the members within any class in the program. B) It allows access to the members only within the same class. Correct! C) It allows access to the members only within subclasses. D) It allows access to the members within the same package.

Which of the following statement is not true about JAVA?

A) It is a high-level programming language B) It is supporting the OOP concept C) It has the Write Once, Run Anywhere policy D) It is an interpreted language CORRECT!

Which statement is not True about local variables?

A) Local variables are declared in the body of a method B) Local variables belongs to methods C) Local variables can be used in any other method Correct! D) Local variables must be initialized

Which of the following is not true about overriding a method?

A) Overriding a method changes the implementation but not the interface B) Overriding is not supported by JAVA Correct! C) You can override a method which is inherited from a parent class D) The method in the subclass must have the same signature (name, parameters, and return type) as the method in the superclass.

Which of the following is not True about constructors ?

A) The constructor is immediately called when an object is created B) The name of the Constructor is usually the same as the Class's name! C) return type of the constructor is always int Correct! D) It is used to set initial values for attributes of the new object

Which statement is not True about the Classes?

A) The public interface of a class should be cohesive B) A class should represent a single concept C) Inheritance is mandatory for all classes Correct! D) In order to identify a class, we should look for the nouns

Which of the following is not True about Unit Testing?

A) The test cases are designed before or during the implementation B) Unit testing means testing one java package at a time Correct! C) Unit tests are designed to test individual units or components of a software. D) We should run the tests after each implementation change

What is the role of the static keyword in Java?

A) To declare a constant variable. B) To set precision for floating point numbers C) To indicate that a method belongs to the class rather than an instance. Correct! D) To create an instance of a super class.

Which of the following is true about the public access modifier?

A) Variables, methods and constructors which are declared public can be accessed by only the accessor methods of that class B) Variables, methods and constructors which are declared public can be accessed by any class lying in same package C) Variables, methods and constructors which are declared public in the superclass can be accessed only by its child class D) Variables, methods and constructors which are declared public can be accessed by any class Correct!

Which of the following statement is not True about JAVA inheritance?

A) We can't inherit the private methods B) In Java, a class can extend multiple classes simultaneously. Correct! C) A subclass can access both public and protected members of the superclass. D) Inheritance increases the reusability of the code

Which of the following is a benefit to using an inner class?

A) can only be local B) needs a new file C) improve encapsulation Correct! D) can have abstract methods -is associated with outer class -improves encapsulation -does not need a new file -can access outer class' members -provides security

Which of the following is not a benefit of generics?

A) increased Reusability B) works with reference data type and primitive type Correct! C) elimination of casts D) type safety

What of the following is not a disadvantage to using linked list?

A) random access is not allow B) extra memory space is required for each element of the list C) not cache friendly D) ease of insertion / deletion

What is an algorithm?

An algorithm is a sequence of computational steps that transform a given input (a set of values) into an output (a set of values)

What form of association uses the "has a" test?

Association Aggregation Correct! Object Composition

What type of association does the following code have? public class UAB { private List students; } public class Student { private String blazerID; private String name; }

Association Aggregation Correct! Object Composition

What identifier sets a variable as true or false?

Boolean Correct! double char int

What is the output of the following code snippet? public class Example { public static void main(String[] args) { int i = 15; if (i % 3 == 0 && i % 5 == 0 { System.out.println("FizzBuzz"); } else if (i % 3 == 0) { System.out.println("Fizz"); } else if (i % 5 == 0) { System.out.println("Buzz"); } else { System.out.println(i); } } }

Buzz FizzBuzz Fizz Buzz FizzBuzz Correct! Fizz

What will be the output of the following code? public static void main(String[] args) { String str1 = new String("CS203"); String str2 = new String("CS203"); System.out.println(str1 == str2); }

CS203 False Correct! True Throws an exception

Assume we have a base (parent) class Vehicle and a derived (child) class Car. Which of the following object creation is not possible?

Car carObj = new Vehicle(); Correct! Vehicle carObj = new Car(); Vehicle vehicleObj = new Vehicle(); Car carObj = new Car();

A Human Object and A Heart Object are an example of what type of association?

Composition Correct! Aggregation Association Object -Human object has a heart and heart can't exist without a human object

What is the output of the following code snippet? public class Main { public static void main(String[] args) { int x = 5; boolean condition = (x > 0) && (x < 10) || (x % 2 == 0); if (condition) { System.out.println("Condition is true."); } else { System.out.println("Condition is false."); } } }

Condition is false. Runtime Error Condition is true. Correct! 1

What is the output of the following code? public class Main { public static void main(String[] args) { int a = 10; int b = 20; boolean c = false; if ( (a >= 10) && (b < 30) && (!c)) { System.out.println("Hello CS203"); } else { System.out.println("Good Luck"); } } }

Good Luck Hello CS203 Correct! Error Hello CS203 Good Luck

________________ is used to run the bytecode on each platform.

Java Virtual Machine Correct! Java Independent Platform Java Time Machine Java Compiler

What is an example of Binary Search pseudocode?

Key Idea: Repeated Halving ▪ To find the phone number of James Harden... ▪ B = phone book ▪ While B islarger than one page: 1. p = page in the middle 2. q = name on first name on p 3. if 'Harden' comes before q: Rip away second half of B else: Rip away first half of B ▪ Scan p line by line for 'James Harden'

What kind of Inner Class is being implemented in the following code? public class OuterClass { public void showMessage() { int age = 55; class InnerClass { public void showMyAge() { System.out.println("Inner Class Message: My age is " + age); } } InnerClass innerObj = new InnerClass(); innerObj.showMyAge(); } }

Method Local Inner Class Correct! Nested Inner Class Anonymous Inner Class Static Nested Inner Class

Which of the following is not a type of inner class in java?

Nested Inner Class Static Nested Inner Class Abstract Inner Class Correct! Method Local Inner Class It is Anonymous Inner Class not Abstract

If the array is already sorted, what is the performance of insertion sort?

O(n)

What form of association uses the "part of" test?

Object Aggregation Composition Correct! Association

What type of association does the following code have? public class Car { private final Engine engine; public Car() { engine = new Engine(); } } class Engine { private String type; }

Object Aggregation Composition Correct! Association

_________ is the base class (super class) of all classes in java.

Pyramid Esspresso Object Correct! Class

What is the pseudocode for Linear Search?

Start from the first element of the array Compare each element of the array one by one If you find the element, return the index If you can not find it, return -1

Which of the following statement is not True about JAVA object?

The object has data The object has operations The object can have only one type of data Correct! The object is reusable

Which of the following statement is not True about JAVA object?

The object is reusable The constructor method is responsible for creating the object. The object can exist in multiple forms The object can have only public methods Correct!

Which of the following statement is not True about JAVA?

The output of the JAVA program is called bytecode Java supports the Boolean data type Functions must declare the types they return The white spaces and the indentation is important Correct!

Constructors are used to ____________

To build a graphical user interface Initialize a newly created object Correct! To create a child class To hide the implementation details

Aggregation is relatively strong association

True False Correct!

Inner Classes can not be declared within the body of another class

True False Correct!

Instance variables belong to the class not any specific object

True False Correct!

It is good practice for instance variables to be public.

True False Correct!

The following is a correct statement to create a subclass public class Faculty extends UABEmployee,Researcher{ }

True False Correct!

We can only construct one object per class

True False Correct!

We can store the integer values inside an arraylist using the following code; Arraylist <int>

True False Correct!

When we are overriding an inherited method, we can use a different type of input parameters

True False Correct!

Association and Composition are two forms of Aggregation

True False Correct!

Composition and Aggregation are two forms of Association

True Correct! False

In general, you should only use an anonymous class if you only need to use it once locally

True Correct! False

Inner Classes can access outer class members

True Correct! False

A derived Class automatically has all the instance variables and public methods that the base Class has, and it can have additional methods and/or instance variables as well

True Correct! False

Do - while loop is guaranteed to run at least one time

True Correct! False

Every variable in JAVA need a data type

True Correct! False

In the OOP concept, data and code are bound together by encapsulation

True Correct! False

JAVA supports multilevel inheritance

True Correct! False

Local variables belong to methods that they are created in

True Correct! False

Method overloading is a feature of OOPs which makes it possible to give the same name to more than one method within a class if the arguments passed differ.

True Correct! False

There is no need to create an object to call the static methods.

True Correct! False

Variables should usually be private!

True Correct! False

When we extend a superclass we have a choice whether or not to override the methods of the superclass

True Correct! False

Which data type is used to create a variable that should store text?

Txt letters String Correct! text

What is the correct way to create an object called myObj of MyClass?

class MyClass = new myObj(); new myObj = MyClass(); MyClass myObj = new MyClass(); Correct! class myObj = new MyClass();

Which keyword is used to create a class in Java?

class() class Correct! className define

Within Java, you need to code your program so that under certain conditions it will skip the current iteration of a for loop. What can be used to accomplish this?

continue Correct! jump ignore skip

What is a Singly Linked List?

each node has a pointer to its successor

Which statement is used to stop a loop?

exit break Correct! kill stop

_______ refers to the object a method is being called on.

extends toString() super this Correct!

_______ refers to the object a method is being called on.

extends toString() this Correct! super

what are the two fields a node contains?

information field (data field) pointer field (next field)

Which of the following is not a primitive type?

int char double object Correct!

The ________ class allows the user to input data from his or her keyboard.

keyboard entry input Scanner Correct!

What is a Doubly Linked List?

nodes have a pointer to successor and predecessor

____________ is an unordered sequence that stores references to objects

objectStorage Constructor Arraylist Correct! objectStorage()

What is a List in Java?

ordered collection of zero or more nodes

When the child class declares a method that has the same type arguments as a method declared by its parent class is called as _____________

overloading overriding Correct! extending this

Assume you have two methods in the Parent class public void method1(){ ... } private void method2(){...} Which of the following is not Possible for the inherited subclass?

public void method1(){...} private void method2(){...} public void method2(){...} private void method1(){...} Correct!

_______ is a keyword which is used to access the methods or member variables of the parent class

super Correct! upperLevel parent this

_______ is a keyword which is used to access the methods or member variables of the parent class

upperLevel super Correct! this parent

The operation _________ yields true if either or both of its operands are true.

|| Correct! & && |

What is Big-O notation and what does it describe?

• Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. • Big O specifically describes the worst-case scenario, and can be used to describe the execution time required


Kaugnay na mga set ng pag-aaral

Psychology: Chapter 4 (State of Consciousness) Quiz

View Set

Bellringers: Chapter 1 Intro to Human Anatomy & Physiology

View Set

final exam west virginia life only

View Set

Maternal Child Nursing Rasmussen Module 2 NCLEX Prep

View Set