1302 Final Study Guide

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the printout for the following statement? System.out.println(5 + 5 /2 * 2 + 5);

14

What is the printed when the code sequence is executed? int i =0; while (i <5) { System.out.print(Math.max(i,2)); i++; }

22234

What are the 4 aspects of a method?

Declaration, call method, Parameter, return

When you extend an array by changing its length property, the number of actual elements does increase by using the .length(). True or False

False

null is instance of String True or False

False

What are the two properties of objects?

State and Behavior

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do? (Initialize a String array)

String[] = {"Huey", "Duey", "Louie"};

What provides infrastructure for application software and consists of operating system and utility software?

System software

To print the following out the following shape what should be line 5? * ** *** **** ***** for( int m =1 ; m<=4; m++) { for( int n =1; n<=m; n++) { System.out.print("*"); } _____________ }

System.out.println();

Comparison operators look at variables but do not change the variables (similarly, logical assertions) True or False

True

Constructors do not have a return type. True or False

True

In Java, a subclass can directly access all the variables and methods of its superclass. True or False

True

The order of declarations usually doesn't matter. True or False

True

When given an object as its argument, System.out.println will automatically call the object's toString method. True or False

True

What is a value we pass into the method as its input we call the method?

argument

What is the output of the following codes? int m = 0; for (int i = 0; i<3; i++) {for (int j = 1; j<4; j++) m++; } System.out.println(m); a) 12 b) 9 c) 16 d) 10

b

What contains declarations of instance variables and instance methods?

class declaration

Which of the following Java variable initializations is invalid? a) int $v10 = 10; b) char $cchaarr__$ = 'a'; c) int _cbabc_ = 10; d) int 4$v10 = 10;

d

What is the output of the following codes? public static void main(String[] args) { int x = 5; strange(x++); System.out.println(x); } public static void strange(int x) { for (;x <10; x++)x= x+1; } a) 11 b) 10 c) 5 d) 6 e) Compiling error

d) 6

When an object variable does not store null, it's illegal to sue the variable to call an instance method. True or False

false

Write a program with loops that will draw a right triangle in the following shape. ********** ********* ******** ******* ****** ***** **** *** ** *

for (int = 10; i>0; i--) { for (int j =i; j>0; j--) { System.out.println("*"); } System.out.println(); }

What is the term when you cannot change an object's instance variable?

immutable

Loops (repeated steps) have _?_ that change each time through a loop. Often these _?_ go through a sequence of numbers.

iteration variables

Consider the following method: public static void mystery (int[] a) { for (int i=1; i<a.length -1; i++) { a[i] = (a[i-1]+a[i+1]/2) /2; } } 1) int[] a1 = {1, 1, 3} mystery(a1); 2) int[] a4 = {-1, 6, 3, 5, -3}; mystery(a4);

1) [1,2,3] 2) [-1,1,3,0,-3]

Assume that BankAccount is a predefined class and that the declaration BankAccount[] firstEmpireBank; has already been performed. Then the following instruction reserves memory space for: firstEmpireBank = new BankAccount[1000]; Choices: a reference variable to the memory that creates 1000 BankAccount objects 1000 reference variables, each of which can point to a single BankAccount entry a single BankAccount entry 1000 BankAccount objects 100 reference variables and 1000 BankAccount entries

1000 reference variables, each of which can point to a single BankAccount entry

What is the printout for the following statement? System.out.println(5 + 5 +"21.0" + 5 + 2 * 5);

1021.0510

If x is an int, where x = 4, what will x be after the following loop terminates? while (x<=100) x*=2;

128

What is the output of the following code? int x = 17; if((x++ >= 18) && (x++ < 65)) x++; System.out.println(x);

18

Show the output of the following value b int a = 5; b = 3; while (a + b < 20) { int temp = a+b; a = b; b = temp; } System.out.println(b);

19

What is the output of the following code? public class Test { public static void main (String[] args) { int[][] matrix = ((1,2,3,4}, {4,5,6,7}, {8,9,10,11}, {12,13,14,15}}; for (int i = 0; i<4; i++) System.out.print(matrix[i][1] + ""); } }

2 5 9 13

Given the StaticEx class and Client class below, what will be the values returned when the following calls are made at the given locations. StaticEx.getCount() (at point 1) StaticEx.getCount() public class StaticEx { private static int count = 4; public StaticEx(){ count -=2; } } public class Client{ public static void main(String[] args) { StaticEx s1 = new StaticEx(); //point 1 StaticEx s2 = new StaticEx(); //point 2 } } Choices: 2,0 0,2 0,0 2,2

2,0

Given the StaticEx class and Client class below, what will be the values returned when the following calls are made at the given locations. StaticEx.getCount() (at point 1) StaticEx.getCount() public class StaticEx { private static int count = 0; public StaticEx(){ count +=2; } } public class Client{ public static void main(String[] args) { StaticEx s1 = new StaticEx(); //point 1 StaticEx s2 = new StaticEx(); //point 2 } } Choices: 4,2 2,2 4,4 2,4

2,4

How many times will the following code print? for (int i =1; i< 10; i++) { if ( i % 3 == 0) System.out.println("Hello World"); }

3

What is the output? public class Location { int lat; int lng; public Location(int intialLat, int initialLng) { lat = intialLat; lng = initialLng; } public String toString () { return lat+","+lng; } } public class ReferenceMystery { public static void mystery(int a, int b, Location loc) { loc.lat = loc.lng - 10; b--; System.out.println(a+" "+b+" "+loc); } public static void main(String[] args) { int a = 3; int b = 9; Location home = new Location(47,122); mystery(a,b,home); System.out.println(a+" "+b+" "+home); } }

3 8 112,122 3 9 112,122

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

5

What will be printed out after executing the following codes? int x = 59; if ((x++ >= 59) && (++x <65)) x++; System.out.println(x);

62

Which of the following is false? A class method has access to the class variables in its class. An instance method has access to the instance variables inside the calling object. An instance method has access to the class variables in its class. A class method has access to the instance variables in its class.

A class method has access to the instance variables in its class.

When call the following method, in terms of the output on the console, which of the following statement is wrong? public static void ifElseMystery(int a, in b) { if(a*2 < b){ a = a * 3; } else if (a > b) { b = b+3; } else { a--; } System.out.println(a + "\\" + b); } Choices : A method call ifElseMystery(4, 5) will output 3\5 A method call ifElseMystery(7, 7) will output 7\7

A method call ifElseMystery(7, 7) will output 7\7

What are the parts on an instance method declaration?

Access modifier, Result type, Method name, Parameters, Body

What is the printout for the following codes? public Class Animal { public void makeSound() { System.out.println("Animal sounds"); } } public class Dog extends Animal { public void makeSound() { System.out.println("Dog barks"); } } public class Cat extends Animal { public void makeSound() { System.out.println("Cat meows"); } public void chaseRat(){ System.out.println("Cat chasing Rats"); } } public class DynamicBindingDemo { public static void main(String[] args){ Animal animal1 = new Animal(); Animal animal2 = new Dog(); Animal animal3 = new Cat(); animal1.makeSound(); animal2.makeSound(); animal3.makeSound(); ((Cat)animal3).chaseRat(); }

Animal Sounds Dog barks Cat Meows Cat chasing Rats

What performs specific tasks for users?

Application software

For each of the points labeled by comments, identify each of the assertions in the table below as either being always true, never true, or sometimes true / sometimes false public static int mystery(Scanner console, int f) { int num = console.nextInt(); int h = 0; //Point A while (f < 5) { //Point B if (num ==0) { f++; //Point C } else { h++; } num = console.nextInt(); } return f; } Which of the following statement is wrong? At Point B, f>=5 is never true At Point A, h==0 is always true At Pont A, num==0 is sometimes true At Point B, num==0 is sometimes true At Point C, f>=5 is always true

At Point C, f>=5 is always true

What asks a question and produce a Yes or No result which we use to control program flow?

Boolean Expressions

What is a program in ROM? It is run by the CPU when power is turned on, transfers operating system from mass storage to main memory and executes jump to operating system.

Boot loader

What is a sequence of directories within directories?

Directory Path

What is a user-created bundle of files and other directories (subdirectories)

Directory, Folder

The methods does not have different numbers of parameters or there must be some difference in the types of parameters. True or False

False

When you extend an array by changing its length property, the number of actual elements does increase by using the .length() True or False

False

What can represent a common super type between different classes without code sharing? Choices: Interface Polymorphism Encapsulation Inheritance Inheritance

Interface

What performs basic required functions. Contains file manager, device drivers, memory manager, and scheduler and dispatcher

Kernel

What allocates space in main memory? It may create the illusion that the machine has more memory than it actually does (virtual memory) by playing as "shell game" in which blocs of data (pages) are shifted back and forth between main memory and mass storage.

Memory Manager

What is a piece of reusable code?

Method

What is the activity of executing a program?

Process

A class can have both class method and instance method. True or False

True

A data field in a class can be of an object type. True or False

True

An instance method can access a class variable. True or False

True

An instance method can access a class variable? True or False

True

An operation that changes an object will also change the object's alias, and vice versa. True or False

True

What communicates with users? Is Text based(Shell) and Graphical user Interface (GUI)

User Interface

What are the two components of an Operating System?

User Interface, Kernel

What is a named place in the memory where a programmer can store data and later retrieve the data using the _?_ "name" Choices Variable Operator Constant Reserved Word

Variable

Which of the following statement is false? When overloading, the access modifier of overloading methods must be different. When overriding, the parameter list of overridden/overriding methods can be different When overloading, the parameter list of overloading methods must be different. When overriding, the child class provides an alternative implementation for a method in parent class. When overloading, the return type of overloading methods can be different.

When overloading, the access modifier of overloading methods must be different.

What is the output of the following codes? public static void main(String[] args) { int[] a1 = {2,3,4}; increase(a1); System.out.println(Arrays.toString(a1)); } public static int[] increase(int[] a) { for (int i = 0; i < a1.length; i++) { a1[i] = a1[i] + i;} return a1; }

[2,4,7]

Given the following declarations, which of the following is/are not arrays int a, b[]; int[] c, d; Choices: d none a, c, and d a and d a

a

Let Account be the bank account class discussed in class. What balance will be stored in acct1, acct2, and acct3 after the following statements have been executed? Account acc1 = new Account(320.00); Account acc2 = acc1; Account acc3 = new Account(100.00); acc1.withdraw(70.00); acc3.deposit(120.00); acc2.deposit(110.00);

acc1 = 360.00 acc2 = 360.00 acc3 = 220.00

What is the term used when an object variable is assigned to another object variable?

aliases

What is the output when the statement System.out.println(8 / 3 * 1.2 + 3/2) is executed? a) 4.1999999999 b) 4.6999999999 c) 3.4 d) 4.7

c) 3.4

Which Java statement produces w on one line and xyz on the next line? a) System.out.println("wxy\tz"); b) System.out.println("w"+"xyz"); c) System.out.println("w\nxyz"); d) System.out.println("w\nx\ny\nz");

c) System.out.println("w\nxyz");

What do Boolean Expressions use to evaluate to -true/false - Yes/No

comparison operators

When an object is created, what initializes the instance variables?

constructor

Most class declarations also contain declarations of _?_, whos job is to initialize objects.

constructors

If a and b are both int arrays, then a = b; will? create an alias copy the 0th integer of b into the 0th element of a copy all integers of b into a return true if each corresponding integer of b is equal to each corresponding integer of a (that is, a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise return true if a and b have the same list of integers and return false otherwise

create an alias

What is the output of the following codes? String str = "I Like Coding."str.toUpperCase(); System.out.println(str.substring(2,5)); a) LIKE b) LIK c) Like d) Lik

d

Considering the following code, if a student's test score is 70, the student will get a letter grade of: if(score>90) grade = 'A'; if(score>80) grade = 'B'; if(score>70) grade = 'C'; if(score>60) grade = 'D'; else grade = 'F';

if(score>60) grade = 'D';

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?\ if(x<0) x--; else x++; if(x<0) x--; else if (x>0) x++; if (x<0) x++; if (x<0) x--; else x= 0; if (x==0) x =0; else x++; x--; if(x>0) x++; else x--;

if(x<0) x--; else if (x>0) x++;

You should add the static keyword in the place of ? in Line ________ in the following code: Line 1 public class Test { Line 2 private int age; Line 3 Line 4 public ? int square(int n) { Line 5 return n*n; Line 6 } Line 7 Line 8 public ? int getAge() { Line 9 return age; Line 10 } Line 11 } Choices: in both line 4 and 8 in Line 8 in Line 4 None

in Line 4

What is the policy of making instance variables private?

information hiding

An _?_ method may require arguments when it's called, and it may return a value.

instance

In Java, performing an operation on an object is done by calling one of the _?_ methods associated with the object.

instance

Behavior is operations that can be performed on the object. What is another term for behavior?

instance methods

State is information stored within the object. What is another term/s for state?

instance variables

When asked to perform an operation on an object, an instance method can examine and/or change the values stored in any of the object's __?__.

instance variables

What are the primitive data types?

int, double, boolean, char

What keyword creates an instance of a class to be created?

new

Do constructors have a result type? Yes or No

no

What value indicates an object variable does not currently point to an object?

null

A program can be though of as a model of reality, with _?_ in the program representing physical _?_

objects

What are instances of a class?

objects

What occurs when a class contains more than one method with the same name?

overlaoding

What is a variable which we use in the method definition that is a "handle" that allows the code in the method to access the arguments for a particular method invocation?

parameter

What is another term for the variable that references the object?

pointer variable

Assume that the Account class contains an instance variable named balance, whose type is double. Write a constructor for this class that initializes the balance to 2000.00

public Account() { this.balance = 2000.00; }

What is the printout for the following statement? System.out.println(!(5 > 2 && -2 > 2) || 5 /2 ==0);

true

In a method if no value is returned, what is the result type?

void

What name is used for a method that returns the contents of an object as a string?

toString

A newly created object is stored in a variable. What does the variable store? The object itself or the reference

reference

What kind of method allows the user to change data stored in private variables?

setter

When invoking a method with an object argument, ___________ is passed. Choices : the contents of the object the object is copied, then the reference of the copied object the reference of the object a copy of the object

the reference of the object

Fix the following code public class employee { private int id; private String name; } public void Employee (int id, String name) { int id = id; name = this.name; }

this.id = id; this.name = name;


Ensembles d'études connexes

Technology Vocabulary in Chinese

View Set