Quiz
CSE 1322 FINAL
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (67)
1The following code will not compile as is. It is missing a line that needs to be inserted where the "//Missing Line" comment is. Which line of code will fix the compile error?
class House {
public int square_footage;
public int stories;
public House() {
square_footage=0;
stories=1;
}
}
class Main {
public static void main(String[] args) {
House h1;
//Missing Line
h1.square_footage=1;
}
}- Anew House(h1);
- Bh1 = new House();
- Ch1.stories = 1;
- Dh1.House();
2A method with a return type of void may still have a return statement in its code.
- ATrue
- BFalse
3Which of the following are valid variable declarations? (Select ALL that are valid)
- Aint a = 1102;
- Blong b=1;
- CJava:
String c = 7;
C#:
string c = 7; - DJava:
String d= "";
C#:
string d= ""; - EJava:
String e = "a" + "b" + 7;
4What is the output of the following code?
Java:
class Numbers {
public int a;
public static int b;
public Numbers(int c) {
a+=c;
b+=c;
}
public int get_b() {
return b;
}
}
class Main {
public static void main(String[] args) {
Numbers n1=new Numbers(2);
Numbers n2=new Numbers(3);
System.out.println("a: "+n2.a+" b: "+Numbers.b);
}
}- Aa: 3 b: 2
- Ba: 3 b: 3
- Ca: 3 b: 0
- Da: 3 b: 5
5Which of the following blocks of code will successfully as a user for a number, multiply by 2, and print the result.
- Aimport java.util.Scanner;
System.out.println("Enter a number to be doubled:");
Scanner myscanner = new Scanner(System.in);
String num=myscanner.NextLine();
num*=2;
System.out.println("Your number doubled is "+num); - Bimport java.util.Scanner;
System.out.println("Enter a number to be doubled:");
Scanner myscanner = new Scanner(System.in);
int num=myscanner.nextInt();
num*=2;
System.out.println("Your number doubled is "+num); - Cimport java.util.Scanner;
int num;
System.out.println("Enter a number to be doubled:");
Scanner myscanner = new Scanner(System.in);
myscanner.nextInt(num);
num*=2;
System.out.println("Your number doubled is "+num);
- Aimport java.util.Scanner;
6Which of the following statements are valid?
- AA constructor can return a integer
- BA constructor can return a char
- CA constructor cannot return anything
- DA constructor can return a void
7What is the output of the following statements:
//Java:
String s="Hi";
for(int i=0;i<3;i++) {
System.out.print("S"+s);
}
//C#:
string s="Hi";
for(int i=0;i<3;i++) {
Console.Write("S"+s);
}- AHi
- BHiHiHi
- CSHiSHiSHi
- DSHiSHi
8What does the following code output?
char letters[]=new char[5];
letters[0]='a';
letters[1]='b';
letters[2]='c';
letters[3]='d';
letters[4]='e';
String x="";
for(int i=4;i>=2;i--) {
x+=letters[i];
}
System.out.println(x);- Aabcd
- Bedcb
- Ced
- Dedc
9What is the output of the following code?
class Main {
public static void swap(String str1, String str2) {
String holdString;
holdString = str1;
str1 = str2;
str2 = holdString;
}
public static void main(String[] args) {
String s1 = "Computers";
String s2 = "Rock";
swap(s1, s2);
System.out.println(s1+" "+s2);
}
}- AComputers Rock
- BRock Computers
- CComputers Computers
- DRock Rock
10What is the output of the following code?
class Main {
public static void addtwo(int[] numArray) {
numArray[0]+=2;
}
public static void main(String[] args) {
int[] myNumbers = new int[] {1,2,3,4,5};
System.out.println(myNumbers[0]);
}
}- A1
- B2
- C3
- D4
11What is the output of the following code?class Main {
public static void dostuff(int x, int y) {
System.out.println("Hi from dostuff 1");
}
public static void dostuff(int x) {
System.out.println("Hi from dostuff 2");
}
public static void dostuff(char x) {
System.out.println("Hi from dostuff 3");
}
public static void dostuff(boolean x) {
System.out.println("Hi from dostuff 4");
}
public static void main(String[] args) {
dostuff(7);
dostuff('c');
dostuff(true);
}
}- AHi from dostuff 2
Hi from dostuff 3
Hi from dostuff 4 - BHi from dostuff 1
Hi from dostuff 2
Hi from dostuff 3 - CHi from dostuff 2
Hi from dostuff 2
Hi from dostuff 2 - DThis produces a compile error saying something like dostuff is already defined.
- AHi from dostuff 2
12What is the output of the following code?
import java.util.ArrayList;
class Stuff {
private int x;
public void setx(int y) {
x=y;
}
public int getx() {
return x;
}
}
class Main {
public static void main(String[] args) {
ArrayList<Stuff> myNumbers = new ArrayList<Stuff>();
for(int i=0;i<5;i++) {
Stuff myStuff = new Stuff();
myStuff.setx(i*10);
myNumbers.add(myStuff);
}
System.out.println(myNumbers.get(2).getx());
}
}- A0
- B2
- C10
- D20
13What is the output of the following code?
class Main {
public static int dostuff(int y) {
return y+=5;
}
public static void main(String[] args) {
int x=5;
for(int i=0;i<2;i++) {
x=dostuff(x);
}
System.out.println("x:"+x);
}
}- Ax:15
- Bx:20
- Cx:5
- Dx:10
14What is the output of the following code?
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
ArrayList<Integer> myNumbers = new ArrayList<Integer>();
myNumbers.add(10);
myNumbers.add(20);
myNumbers.add(30);
myNumbers.add(40);
System.out.println(myNumbers.get(myNumbers.size()-1));
}
}- A10
- B20
- C30
- D40
15The following code will compile and output 8?
class Stuff {
public int x=7;
}
class Main {
public static void main(String[] args) {
Stuff.x=8;
System.out.println(Stuff.x);
}
}- ATrue
- BFalse
16What is the output of the following code?
class Stuff {
public int number=1;
}
class Main {
public static void do_things(int y) {
y+=3;
}
public static void do_other_things(Stuff y) {
y.number+=3;
}
public static void main(String[] args) {
int a=3;
Stuff myStuff = new Stuff();
do_things(a);
do_other_things(myStuff);
System.out.println("a:"+a+" myStuff.number:"+myStuff.number);
}
}- Aa:6 myStuff.number:1
- Ba:6 myStuff.number:4
- Ca:3 myStuff.number:4
- Da:3 myStuff.number:1
17What is the output of the following code?
class Animal {
public void sound() {
System.out.println("eek");
}
}
class Cow extends Animal {
@Override
public void sound() {
System.out.println("moo");
}
}
class Dog extends Animal {
}
class Main {
public static void main(String[] args) {
Animal a1=new Animal();
a1.sound();
Cow a2=new Cow();
a2.sound();
Dog a3=new Dog();
a3.sound();
}
}- Aa3.sound() will produce a compile error.
- Beek
moo
woof - Cmoo
eek
moo - Deek
moo
eek
18What is the output of the following code?
class A {
public void do_it() {
System.out.println("A");
}
}
class B extends A {
@Override
public void do_it() {
System.out.println("B");
}
}
class Main {
public static void main(String[] args) {
A myClass=new B();
myClass.do_it();
}
}- AA
- BB
- CAB
- DThis code does not compile.
19Consider the following code class for XYZ
public class XYZ
{
private int myNum;
public XYZ (int n1) {
myNum = n1;
}
}
Which of the following statements is TRUE about class XYZ- AA subclass cannot inherit from class XYZ
- BClass XYZ inherits from the Object class
- CClass XYZ has a child class called the Object class
20What is the output of the following code?
class A {
public void do_it() {
System.out.println("A");
}
}
class B extends A {
public void do_stuff() {
System.out.println("B");
}
}
class Main {
public static void main(String[] args) {
A myClass=new A();
myClass=new B();
myClass.do_it();
}
}- AA
- BB
- CA
B - DThis code does not compile
21According to the following UML, if a new object of B is created in main as follows:
B myB = new B();
Which of the following statements is NOT valid in main?
- AmyB.do_b_stuff1();
- BmyB.do_b_stuff2();
- CmyB.do_stuff1();
- DmyB.do_stuff3();
22Given the following UML, which statement below is not valid?

- AA myvar = new A();
- BB myvar = new B();
- CC myvar = new C();
- DA myvar = new B();
- EB myvar = new A();
- FA myvar = new C();
23Given the following code, which of the following is the correct definition for class B, such that the output of the program is 1 2 3 :
[Hint: Pay close attention to the Access Modifiers]
public class A {
private int x;
private int y;
public A(int a, int b) {
x=a;
y=b;
}
@Override
public String toString() {
return x+" "+y;
}
}
//Class B goes here.
class Main {
public static void main(String[] args) {
B myB=new B(1,2,3);
System.out.println(myB);
}
}
- Aclass B extends A {
private int z;
public B(int a, int b, int c) {
super(a,b);
z=c;
}
@Override
public String toString() {
return x+" "+y+" "+z;
}
} - Bclass B extends A {
private int z;
public B(int a, int b, int c) {
super(a,b);
z=c;
}
@Override
public String toString() {
return super.toString()+" "+z;
}
} - Cclass B extends A {
private int z;
public B(int a, int b, int c) {
super(a,b);
z=c;
}
@Override
public String toString() {
return super()+" "+z;
}
} - Dclass B extends A {
private int z;
public B(int a, int b, int c) {
super(a,b);
z=c;
}
@Override
public String toString() {
return super.x+" "+super.y+" "+z;
}
}
- Aclass B extends A {
24Which of the following constructors will NOT successfully set the two attributes in this class:
class Movie {
public double timeInSeconds;
private String rating;
}- Apublic Movie(double time, String rating) {
this.timeInSeconds=time;
this.rating=rating;
} - Bpublic Movie(double time, String rating) {
time=timeInSeconds;
rating=this.rating;
} - Cpublic Movie(double time, String rating) {
timeInSeconds=time;
this.rating=rating;
}
- Apublic Movie(double time, String rating) {
25Will the following code compile?
interface IA {
public void do_stuff1();
}
abstract class B {
public abstract void do_stuff2();
}
class C extends B implements IA {
@Override
public void do_stuff1() {
int a=1;
}
@Override
public void do_stuff2() {
int b=1;
}
}
class Main {
public static void main(String[] args) {
C myC = new C();
}
}- ANo, Class C can't extend one class (B) and implement an interface (1A), it can only do one or the other
- BNo, Class C doesn't correctly override do_stuff2()
- CNo, class C cannot be instantiated because it implements an interface.
- DYes
26Will the following code compile?
abstract class A {
public int do_stuff1() {
return 3;
}
}
class B extends A {
@Override
public int do_stuff1() {
return 4;
}
public int do_stuff2() {
return 7;
}
}
class Main {
public static void main(String[] args) {
//Note the polymorphism:
A myB = new B();
myB.do_stuff1();
myB.do_stuff2();
}
}- ANo, class A is marked abstract, but has no abstract methods, and that is not allowed.
- BNo, class A has no do_stuff2() therefore you can't call do_stuff2() on myB in main.
- CNo, class A is abstract, so you can't call do_stuff1() even though there is an override in class B.
- DYes
27The following is a valid (i.e. will compile) abstract class definition:
abstract class A {
public int do_stuff1() {
return 3;
}
public int do_stuff2() {
return 4;
}
}- ATrue
- BFalse
28Given the following code, which method will cause a compile error:
abstract class A {
public int do_stuff1() {
return 3;
}
public abstract int do_stuff2() {};
public void do_stuff3() {
return;
}
public abstract int do_stuff4();
}- Ado_stuff1()
- Bdo_stuff2()
- Cdo_stuff3()
- Ddo_stuff4()
- EMore than one method will cause a compile error.
29Will the following code compile?
interface IA {
public void do_stuff1();
public void do_stuff2();
}
class C implements IA {
@Override
public int do_stuff1() {
return 1;
}
@Override
public void do_stuff2() {
int b=1;
}
}
class Main {
public static void main(String[] args) {
C myC = new C();
}
}- ANo class C does not implement do_stuff1() appropriately.
- BNo, interface IA cannot have 2 virtual methods.
- CNo, class C cannot be instantiated because it implements an interface.
- DYes
30When a set of methods have the same name but different types/number of parameters in the same class, they are called:
- AOverridden methods
- BOverload methods
- CConstructors
- DtoString() methods
31Will the following code compile?
interface IA {
public void do_stuff1();
}
interface IB {
public void do_stuff2();
}
class C implements IA,IB {
@Override
public void do_stuff1() {
int a=1;
}
@Override
public void do_stuff2() {
int b=1;
}
}
class Main {
public static void main(String[] args) {
C myC = new C();
}
}- ANo, class C is not allowed to implement IA and IB.
- BNo, you can't instantiate an object of type C.
- CNo, methods in an interface can't have a void return type.
- DYes
32Will the following code compile?
abstract class A {
public int do_stuff1() {
return 3;
}
public abstract int do_stuff2();
}
class B extends A {
@Override
public int do_stuff1() {
return 4;
}
@Override
public int do_stuff2() {
return 7;
}
}
class Main {
public static void main(String[] args) {
B myB = new B();
myB.do_stuff1();
myB.do_stuff2();
}
}- ANo, you can't have a concrete method like do_stuff1() in an abstract class like A
- BNo, you can't override do_stuff1() in class B
- CNo, you can't call do_stuff2() on the object myB.
- DYes
33Given the following method:
public static int recursive(int n,int m) {
if(n<=1) {
return 1;
}
else {
return m+recursive(n/2,m*2);
}
}
What is the value of x after the following call:
int x = recursive(6,8);- A25
- B17
- C19
- D23
34What is the output of the following code?
class Main {
public static String question(String x) {
if(x.length()==0) {
return x;
}
else {
return "X"+question(x.substring(0,x.length()-1));
}
}
public static void main(String[] args) {
String y=question("ABCDE");
System.out.println(y);
}
}- AABCDE
- BEDCBA
- CXEXDXCXBXA
- DXXXXX
35Given the following method:
public static int do_stuff(int x) {
if(x<=0) {
return 1;
}
else {
return do_stuff(x-1)+do_stuff(x-2);
}
}
What will the value of ans be after the method is called like this:
int ans=do_stuff(2);- A1
- B2
- C3
- D4
36If a recursive method has no base case (bottom), or if the base case is never reached, it will become infinite and the result will be stack overflow error.
- ATrue
- BFalse
37This method is designed to find the lowest integer in an array. Which of the following choices is the correct recursive call?
public static int lowest(int[] a,int start) {
if(start>=a.Length-1) {
return a[start];
}
else {
//MISSING RECURSIVE CALL GOES HERE
}
}- Areturn lowest(a,start+1);
- Bif(a[start]<a[start+1]) {
return a[start];
}
else {
return lowest(a,start-1);
} - Cif(start<lowest(a,start+1)) {
return start;
}
else {
return lowest(a,start+1);
} - Dif(a[start]<lowest(a,start+1)) {
return a[start];
}
else {
return lowest(a,start+1);
}
38The following is the code to play a guessing game. It will keep prompting until the user guesses the correct answer (50). While the user is guessing it'll count how many attempts it took the user to guess correctly. When the user correctly guesses the number, it outputs the number of guesses it took.
What is the correct recursive statement that is missing from guess_num() method?
import java.util.Scanner;
class Main {
public static int guess_num(int answer,int tries) {
Scanner myScan=new Scanner(System.in);
System.out.println("Guess a number");
int guess=myScan.nextInt();
if(guess==answer) {
System.out.println("Correct");
return tries;
}
else {
//What goes here?
}
}
public static void main(String[] args) {
int guesses=guess_num(50,1);
System.out.println("It took you "+guesses+" guesses");
}
}- Areturn guess_num(answer+1,tries);
- Breturn guess_num(answer,tries);
- Creturn guess_num(answer,tries-1);
- Dreturn guess_num(answer,tries+1);
39Given the following method:
public static int recursive(int n) {
if(n<=1) {
return 1;
}
else {
return 2+recursive(n/2);
}
}
What is the value of x after the following call:
int x = recursive(3);- A0
- B1
- C2
- D3
40Given this method:
public static int do_stuff(int x) {
if(x==0) {
return 1;
}
else {
return do_stuff(x-1);
}
}
What will the method return if called as follows:
do_stuff(15);- A30
- B15
- C3
- D1
41What is the output of the following code:
class Main {
public static void do_stuff() {
int[] myNums = new int[5];
myNums[5]=1;
}
public static void main(String[] args) {
try {
do_stuff();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}- ANo output from either language
- BJava: Exception Caught
C#: Exception Caught - CJava:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
at Main.do_stuff(Main.java:5)
at Main.main(Main.java:10)
C#:
Unhandled Exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MainClass.Main (System.String[] args) [0x00000] in <f69c1c562c914f118dbf07bc5c874773>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MainClass.Main (System.String[] args) [0x00000] in <f69c1c562c914f118dbf07bc5c874773>:0 - DJava: Index 5 out of bounds for length 5
C#: Index was outside the bounds of the array.
42If you call do_stuff() from main, what if any exception will you see?
public static void do_stuff() {
int[] myNums = new int[5];
myNums[5]=1;
}- AIt will not throw any exception
- BJava: Exception
C#: Exception - CJava: ArrayIndexOutOfBoundsException
C#: IndexOutOfRangeException
43What is the output of the following code:
class Wrong extends Exception {
public Wrong(String message) {
super(message);
}
}
class Main {
public static void doStuff(int x) throws Wrong {
if(x<0) {
throw new Wrong("Too Low");
}
else if(x==0) {
System.out.println(x);
}
else {
doStuff(x-1);
System.out.println(x);
}
}
public static void main(String[] args) {
try {
doStuff(3);
System.out.println("---");
doStuff(-1);
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}- A0
1
2
3
---
Too Low - B3
2
1
0
---
-1 - C0
1
2
3
--- - D3
2
1
---
Too Low
- A0
44What is the output of the following code:
class Main {
public static void main(String[] args) {
int[] myArray = new int[5];
try {
for(int i=0;i<=5;i++) {
myArray[i]=i;
}
System.out.println(myArray[3]);
}
catch(Exception e) {
System.out.println("Something went wrong");
}
}
}- ASomething went wrong
- BSomething went wrong
3 - C3
- D2
45The try-catch construct consists of one try block and one or more catch blocks. The try block contains the code that could throw exceptions.
- ATrue
- BFalse
46The code within the finally block is always executed, no matter how the program flow leaves the try block. This guarantees that the finally block will be executed even if an exception is thrown.
- ATrue
- BFalse
47What is the output of the following code:
class Main {
public static void do_stuff() {
int[] myNums = new int[5];
myNums[5]=1;
}
public static void main(String[] args) {
try {
do_stuff();
}
catch(Exception e) {
System.out.println("A");
}
finally {
System.out.println("X");
}
}
}- ANo output
- BA
- CA
X - DX
48What is the output of the following code:
class Main {
public static void do_stuff() {
int[] myNums = new int[5];
myNums[5]=1;
}
public static void main(String[] args) {
try {
do_stuff();
}
catch(IndexOutOfBoundsException e) {
System.out.println("A");
}
catch(RuntimeException e) {
System.out.println("B");
}
catch(Exception e) {
System.out.println("C");
}
}
}- ANo output
- BA
- CABC
- DC
49Assume you have a file called QuizGrades.csv with the following content:
Student1,100,90,80,90,80
Student2,70,80,85,85,80
Student3,100,100,100,95,100
Student4,70,70,80,70,80
Student5,90,90,90,90,100
Which of the following lines is the correct way to open a text file such as the above for reading.- AFile myFile = new File("QuizGrades.csv");
Scanner myScan = new Scanner(myFile); - BScanner myScan = new Scanner("QuizGrades.csv");
- CText myFile = new Text("QuizGrades.csv");
Scanner myScan = new Scanner(myFile);
- AFile myFile = new File("QuizGrades.csv");
50Assume you have a file called QuizGrades.csv with the following content:
Student1,100,90,80,90,80
Student2,70,80,85,85,80
Student3,100,100,100,95,100
Student4,70,70,80,70,80
Student5,90,90,90,90,100
Which of the following code snips correctly reads each line from the file correctly assigning it to a variable called line.
You can assume the previous question correctly opened the file, and you have a variable myScan which allows you to access the file.- Awhile(myScan.hasNextLine()) {
String line=myScan.readLine();
} - Bwhile(! myScan.hasNextLine()) {
String line=myScan.nextLine();
} - Cwhile(myScan.hasNextLine()) {
String line=myScan.nextLine();
}
- Awhile(myScan.hasNextLine()) {
51Assume you have a file called a.txt with the following content :
jane,100
tim,80
janet,40
What is the output of the following code
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
class Score {
public String name;
public int theScore;
public Score(String name, int theScore) {
this.name=name;
this.theScore=theScore;
}
}
class Main {
public static void main(String[] args) {
ArrayList<Score> scoreCard = new ArrayList<Score>();
try {
File scoreFile = new File("a.txt");
Scanner sf = new Scanner(scoreFile);
while(sf.hasNextLine()) {
String line=sf.nextLine();
String[] parts=line.split(",");
Score newScore = new Score(parts[0],Integer.parseInt(parts[1]));
scoreCard.add(newScore);
}
}
catch(IOException e) {
System.out.println(e.getMessage());
}
System.out.println(scoreCard.get(1).name);
}
}- AIndex out of Bounds/Range Exception
- Bjanet
- C80
- Dtim
52Which of the following will successfully write the word Output to the file a.txt in the current working directory?
- Aimport java.io.*;
class Main {
public static void main(String[] args) {
File myFile = new File("a.txt");
PrintWriter sr = new PrintWriter(myFile);
sr.println("Output");
sr.close();
}
} - Bimport java.io.*;
class Main {
public static void main(String[] args) {
try {
File myFile = new File("a.txt");
PrintWriter sr = new PrintWriter(myFile);
sr.println("Output");
sr.close();
}
}
} - Cimport java.io.*;
class Main {
public static void main(String[] args) {
try {
File myFile = new File("a.txt");
PrintWriter sr = new PrintWriter(myFile);
sr.println("Output");
sr.close();
}
catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
- Aimport java.io.*;
53The Socket object in Java, and the TCPClient object in C# can be used to read information from a remote server, but not write to it?
- ATrue
- BFalse
54Which of the following statements is true?
- AA try/catch block should never be used with fileIO
- BA try/catch block should be used only when writing to a file
- CA try/catch block should be used only when reading from a file.
- DA try/catch block should be used when reading and writing to a file.
55Given the previous 3 questions, the following would be an appropriate catch block?
catch(IOException e) {
System.out.println("Error reading file: "+e.getMessage());
}- ATrue
- BFalse
56After executing the following code, what will be the contents of A.txt?
import java.io.*;
import java.io.File;
import java.io.IOException;
class Main {
public static void write_file(String filename, String line, int x) {
try {
File myFile=new File(filename);
PrintWriter theFile = new PrintWriter(myFile);
for(int i=0;i<x;i++) {
theFile.println(line);
}
theFile.close();
}
catch(IOException e) {
System.out.println("Error reading file: "+e.getMessage());
}
}
public static void main(String[] args) {
write_file("A.txt","Hi",3);
}
}- AA.txt wll not exist after running this code.
- BA.txt will be empty
- CA.txt will contain the word Hi on three lines
- DA.txt will contain the word Hi on six lines
57What does the following statement do?
Thread.sleep(10000);- ACauses the current thread to exit
- BCauses the current thread to pause for 10,000 seconds
- CCauses the current thread to pause for 10 seconds
- DCauses the current thread to pause for 1 second
58All programs have at least one thread?
- ATrue
- BFalse
59If you wanted to find if a particular number was present in an array of one million integers, which of the following approaches will not work?
- AUse a simple loop in a single thread, that looks in each of the cells.
- BUse a multithreaded approach, where you have 10 threads each of which looks in 100,000 cells.
- CUsing a multithreaded approach, where you have 100 threads each of which looks at 10,000 cells.
- DThey would all work.
60What is the output of the following code?
class MyFirstThread implements Runnable {
static int next_tid=1;
int tid;
public MyFirstThread() {
tid=next_tid++;
}
public void run() {
System.out.println("I'm thread "+tid);
}
}
class Main {
public static void main(String[] args) {
MyFirstThread t1 = new MyFirstThread();
MyFirstThread t2 = new MyFirstThread();
MyFirstThread t3 = new MyFirstThread();
System.out.println("Let's go!");
Thread thread1 = new Thread(t1);
Thread thread2 = new Thread(t2);
Thread thread3 = new Thread(t3);
System.out.println("Done");
}
}- ALet's go!
I'm thread 1
I'm thread 2
I'm thread 3
Done - BLet's go!
I'm thread 3
I'm thread 2
I'm thread 1
Done - CLet's go!
Done - DIt's impossible to tell the order the statements will appear in.
- ALet's go!
61What is the output of the following code?
import java.util.ArrayList;
class Widget {
public String name;
}
class Inventory {
public static ArrayList<Widget> factoryInventory = new ArrayList<Widget>();
}
class Factory extends Inventory implements Runnable {
public void run() {
for(int i=0;i<100;i++) {
Widget newWidget = new Widget();
newWidget.name="Widget"+i;
factoryInventory.add(newWidget);
}
}
}
class Main {
public static void main(String[] args) {
Inventory myInventory=new Inventory();
Thread[] factories = new Thread[100];
for(int i=0;i<100;i++) {
factories[i]=new Thread(new Factory());
factories[i].start();
}
System.out.println(myInventory.factoryInventory.size());
}
}- A100
- B1000
- C10000
- DThe output will be different each time you run it
62Making a program multithreaded will always ensure it runs faster?
- ATrue
- BFalse
63Code written to take advantage of parallel processing will always run faster than code which is not written for parallel processing?
- ATrue
- BFalse
64What method will contain the body of the thread?
- AJava:
run()
C#: You can call it anything you want, but you reference it in ThreadStart( ) - BJava:
start()
C#
Start() - CJava:
Execute()
C#: Run() - DJava:
start()
C#:
Execute()
- AJava:
65A list is a linear collection
- ATrue
- BFalse
66Pressing a GUI button normally causes an event to occur.
- ATrue
- BFalse
67In GUI coordinate system, which of the following positions refers to the coordinates (0,0)?
- AThe bottom left corner of the GUI box
- BThe top left corner of the GUI box
- CThe top right corner of the GUI box
- DThe bottom right corner of the GUI box
Information
- Description
- Computer Science Quiz on CSE 1322 FINAL, created by Emily Mack on 31/07/2022.
- Author
- Emily Mack
- Language
- English
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz