CSE 1322 FINAL!! (Spring semester 2023)

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/86

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

87 Terms

1
New cards

Which of the following are valid variable declarations:

int a=1102;

long b=1;

Java:String c=7;

C#:

string c=7;

Java:String d="";

C#:string d="";

Java:String e="a"+"b"+7;

C#:string e="a"+"b"+7;

int a=1102;

Java:String c=7;C#:

string c=7

Java:String e="a"+"b"+7;

C#:string e="a"+"b"+7;

2
New cards

Which of the following blocks of code will successfully ask a user for a number, multiply that number by 2, and print the result

A.Java

import 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);

B.Java

import 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);

C.Java

import 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);

Java:

import 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);

3
New cards

Arrays are not fixed length and can grow or shrink depending on if the size of the data set varies.

False

4
New cards

What does the following code output?

Java

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);

abcd

edcb

ed

edc

edc

5
New cards

What is the output of the following code?

Java

class Numbers {

public int a;

public int b;

public Numbers(int c) {

a=c;

b=c*2;

}

@Override public String toString() {

return("a: "+a+" b: "+b); }}

class Main {public static void main(String[] args) {

Numbers n1=new Numbers(2);

System.out.println(n1); }}

n1

No output or an error

a: 2 b: 4

Numbers

a: 2 b: 4

6
New cards

How many parameters does a default constructor have?

3

2

1

0

0

7
New cards

Which of the following methods are invalid?

Java

public static void do_stuff_1() {return;}public static int do_stuff_2() {return 2;}public static char do_stuff_3() {return 'c';}public static boolean do_stuff_4() {return false;}

do_stuff_1()

do_stuff_2()

do_stuff_3()

do_stuff_4()

They are all valid

they are all valid

8
New cards

The 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);

}

}

false

9
New cards

class Stuff {

public int number=1;

}

class Main {

public static void main(String[] args) {

Stuff myStuff = new Stuff();

myStuff.number+=3;System.out.println("myStuff.number:"+myStuff.number);

myStuff = new Stuff();System.out.println("myStuff.number:"+myStuff.number);}}

myStuff.number:4myStuff.number:4

myStuff.number:1myStuff.number:1

myStuff.number:1myStuff.number:4

myStuff.number:4myStuff.number:1

myStuff.number:4

myStuff.number:1

10
New cards

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);}}

x:15

x:20

x:5

x:10

x:15

11
New cards

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 myNumbers = new ArrayList();

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());

}

}

0

2

10

20

20

12
New cards

What is the output of the following code?

What 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); }}

a:6 myStuff.number:1

a:6 myStuff.number:4

a:3 myStuff.number:4

a:3 myStuff.number:1

a:3 myStuff.number:4

13
New cards

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); }}

Hi from dostuff 2

Hi from dostuff 3

Hi from dostuff 4

Hi from dostuff 1

Hi from dostuff 2

Hi from dostuff 3

Hi from dostuff 2

Hi from dostuff 2

Hi from dostuff 2

This produces a compile error saying something like dostuff is already defined.

Hi from dostuff 2

Hi from dostuff 3

Hi from dostuff 4

14
New cards

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]);

}

}

1

2

3

4

1

15
New cards

import java.util.ArrayList;

class Main {

public static void main(String[] args) {

ArrayList myNumbers = new ArrayList();

myNumbers.add(10);myNumbers.add(20);myNumbers.add(30);myNumbers.add(40);

System.out.println(myNumbers.get(myNumbers.size()-1));}}

10

20

39

40

40

16
New cards

In dynamic binding or late binding, the type of object is determined at run-time.T/F

True

17
New cards

An interface can provide implementations for any of its methods, and so can an abstract class.

True

False

False

18
New cards

OOP feature which derives a class from another class

Polymorphism

Inheritance

Encapsulation

Data hiding

Inheritance

19
New cards

Why does the following code not compile?

Java

public class XYZ {

private int myNum;

public XYZ() {

myNum=0;

}

public XYZ(int n1) {

myNum=n1; }}

public class ABC extends XYZ {

private int num2;

public ABC() {

myNum=0;

num2=0; }

pubilc ABC(int n1) {

myNum=n1;

num2=n1*2;

}}

class Main { public static void main(String[] args) {

ABC myABC = new ABC(); }}

A.myNum is defined as private in XYZ and as such is inaccessable in ABC.

B.class ABC cannot have private attributes because it's inheriting from XYZ

C.class ABC is not allowed to inherit from class XYZ

D.You cannot instantiate an object of type ABC, you can only instantiate objects of type XYZ

A.myNum is defined as private in XYZ and as such is inaccessable in ABC.

20
New cards

To facilitate encapsulation, most attributes and methods in a class should be private?

True

False

True

21
New cards

Given the following UML, which statement below is not valid?

A myvar = new A();

B myvar = new B();

C myvar = new C();

A myvar = new B();

B myvar = new A();

A myvar = new C();

B myvar = new A();

22
New cards

What is the output of the following code?Java

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(); }}

A

B

AB

This code does not compile

A

23
New cards

What 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(); }}

a3.sound() will produce a compile error.

eek

moo

woof

moo

eek

moo

eek

moo

eek

eek

moo

eek

24
New cards

Will 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();

}

}

No class C does not implement do_stuff1() appropriately.

No, interface IA cannot have 2 virtual methods.

No, class C cannot be instantiated because it implements an interface.

Yes

No class C does not implement do_stuff1() appropriately.

25
New cards

Will the following code compile?

abstract class A {

private int x;

public A() {

x=7;

}

public A(int y) {

x=y;

}

public abstract int do_stuff1();

public abstract int do_stuff2();

}

class B extends A {

public B() {

super(7);

}

public B(int y) {

super(y);

}

@Override

public int do_stuff1() {

return 4;

}

@Override

public int do_stuff2() {

return 4;

}

}

class Main {

public static void main(String[] args) {

B myB = new B(5);

}

}

No, class A cannot have a constructor since it's abstract.

No, class B can't have a constructor since it's inheriting from an abstract class A.

No, you can't use super/base to call a constructor in an abstract class.

Yes

Yes

26
New cards

The 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;

}

}

True

False

true

27
New cards

What is the output of the following code?

interface IA {public void do_stuff1();}

abstract class B {

public abstract void do_stuff2();

public int do_stuff3() {

return 2;

}

}

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();

System.out.println(myC.do_stuff3());

}

}

This code doesn't compile. Object myC doesn't have a method do_stuff3()

1

2

3

2

28
New cards

What is the output of the following code?

class Parent{

public int stuff() {

return 1;

}

}

class ChildOne extends Parent {

@Override

public int stuff() {

return 2;

}

}

class ChildTwo extends Parent {

@Override

public int stuff() {

return 3;

}

}

class MainClass {

public static void Main (string[] args) {

Parent var1=new Parent();

ChildOne var2=new ChildOne();

ChildTwo var3=new ChildTwo();

Parent var4=new ChildOne();

Parent var5=new ChildTwo();

int sum=var1.stuff() + var2.stuff() + var3.stuff() + var4.stuff() + var5.stuff();

System.out.println ("Sum is "+sum);

}

}

9

10

11

12

11

29
New cards

Will 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();

}

}

No, Class C can't extend one class (B) and implement an interface (1A), it can only do one or the other.

No, Class C doesn't correctly override do_stuff2()

No, class C cannot be instantiated because it implements an interface.

Yes

Yes

30
New cards

Will 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();

}

}

No, class C is not allowed to implement IA and IB.

No, you can't instantiate an object of type C.

No, methods in an interface can't have a void return type.

Yes

Yes

31
New cards

Given 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();

}

do_stuff1()

do_stuff2()

do_stuff3()

do_stuff4()

More than one method will cause a compile error.

do_stuff2()

32
New cards

This 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

}

}

return lowest(a,start+1);

if(a[start]

if(a[start]

33
New cards

Given the following method:

public static int myFunc(int x, int y) {

if(x==0) {

return y;

}

else {

return myFunc(x-1,y+1);

}

}

What is the value of x after the following call:int x = myFunc(0,4);

4

6

8

Infinite recursion

4

34
New cards

Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body.

True

False

True

35
New cards

Given 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);

0

1

2

3

3

36
New cards

The following recursive method takes in an array of characters, and finds the highest letter alphabetically in the array. i.e. if passed the following characters: x a b p s, it should return x because x is the last of those alphabetically.

Choose the correct base condition that completes the code correctly from the choices below.

public static char last_letter_used(char[] charArray, int position) {

//Base condition goes here

else {

if(charArray[position]>last_letter_used(charArray,position+1)) {

return charArray[position];

}

else {

return(last_letter_used(charArray,position+1));

}

}

}

if(position==0) {

return charArray[position];

}

JavaC#if(position==charArray.length) { return charArray[position];}if(position==charArray.Length) { return charArray[position];}

JavaC#if(position==charArray.length-1) { return charArray[position];}if(position==charArray.Length-1) { return charArray[position];}

if(charArray.length==0) {

return charArray[position];

}

if(position==charArray.length-1) {

return charArray[position];

}

37
New cards

To successfully sum all integers in an array, what should the missing line of code be:

public static int sum_array(int[] myArray,int start) {

if(start>myArray.length-1) {

return 0;

}

//What goes here?

}

return(sum_array(myArray,start+1));

return(myArray[start]+sum_array(myArray,start+1));

return(myArray[start]+sum_array(myArray,start));

return(myArray[start]+sum_array(myArray,start-1));

return(myArray[start]+sum_array(myArray,start+1));

38
New cards

Given the following code:

public static int do_stuff(int x) {

if(x==0) {

return 1;

}

else {

return 1 + do_stuff(x-2);

}

}

What is returned from this code if called as follows:

do_stuff(3);

1

2

3

This code crashes with a stack overflow

This code crashes with a stack overflow

39
New cards

Given the following method:

public static int myFunc(int x, int y) {

if(x==0) {

return y;

}

else {

return myFunc(x-1,y+1);

}

}

What is the value of x after the following call:int x = myFunc(2,4);

4

6

8

Infinite recursion

6

40
New cards

The try-catch construct consists of one try block and one or more catch blocks. The try block contains the code that could throw exceptions.

True

False

True

41
New cards

The 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.

True

False

True

42
New cards

What 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");

}

}

}

No output

A

AX

X

A

X

43
New cards

What 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();

System.out.println("A");

}

catch(Exception e) {

System.out.println("B");

}

}

}

No output

AB

A

B

B

44
New cards

Given the following code:

public static void check_age(int age) throws Exception {

if(age<0) {

throw new Exception("Age cannot be below 0");

}

else if(age>140) {

throw new Exception("That seems too high.");

}

}

What is the correct way to call this method such that your code doesn't crash if an invalid age is entered?

try {

check_age(age);

}

catch(Exception e) {

System.out.println(e.getMessage());

}

if(! check_age(age)) {

System.out.println(Exception.getMessage());

}

try {

check_age(age);

}

else {

System.out.println(e.getMessage());

}

try {

check_age(age);

}

catch {

System.out.println(e.getMessage());

}

try {

check_age(age);

}

catch(Exception e) {

System.out.println(e.getMessage());

}

45
New cards

An exception is a notification that something interrupts the normal program execution. Exceptions provide a programming paradigm for detecting and reacting to unexpected events.

True

False

True

46
New cards

What 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");

}

}

}

No output

A

ABC

C

A

47
New cards

If 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;}

It will not throw any exception

Java: Exception

C#: Exception

Java: ArrayIndexOutOfBoundsException

C#: IndexOutOfRangeException

Java: ArrayIndexOutOfBoundsException

C#: IndexOutOfRangeException

48
New cards

Given the previous 3 questions, the following would be an appropriate catch block?

catch(IOException e) {

System.out.println("Error reading file: "+e.getMessage());

}

True

False

True

49
New cards

Assume you have a file called QuizGrades.csv with the following content:

Student1,100,90,80,90,80Student2,70,80,85,85,80Student3,100,100,100,95,100Student4,70,70,80,70,80Student5,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.

while(myScan.hasNextLine()) {

String line=myScan.readLine();}

while(! myScan.hasNextLine()) {

String line=myScan.nextLine();}

while(myScan.hasNextLine()) {

String line=myScan.nextLine();}

while(myScan.hasNextLine()) {

String line=myScan.nextLine();}

50
New cards

Which of the following will successfully write the word Output to the file a.txt in the current working directory?

import 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();

}

}

import 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();

}

}

}

import 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());

}

}

}

import 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());

}

}

}

51
New cards

After 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

A.txt will contain the word Hi on three lines

52
New cards

Assume you have a file called a.txt with the following content :

jane,100tim,80janet,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 scoreCard = new ArrayList();

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);

}

}

Index out of Bounds/Range Exception

janet

80

tim

tim

53
New cards

Assume you have a file called QuizGrades.csv with the following content:

Student1,100,90,80,90,80Student2,70,80,85,85,80Student3,100,100,100,95,100Student4,70,70,80,70,80Student5,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.

File myFile = new File("QuizGrades.csv");

Scanner myScan = new Scanner(myFile);

Scanner myScan = new Scanner("QuizGrades.csv");

Text myFile = new Text("QuizGrades.csv");

Scanner myScan = new Scanner(myFile);

File myFile = new File("QuizGrades.csv");

Scanner myScan = new Scanner(myFile);

54
New cards

Which of the following statements is true?

A try/catch block should never be used with fileIO

A try/catch block should be used only when writing to a file

A try/catch block should be used only when reading from a file.

A try/catch block should be used when reading and writing to a file.

A try/catch block should be used when reading and writing to a file.

55
New cards

The 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?

True

False

False

56
New cards

Given the following class, which of the following statements are invalid?

class House {public int square_footage;public int stories;

public House() {square_footage=0;stories=1;}

public House(int sf, int s) {square_footage=sf;stories=s;}}

House h1=new House(1500,1,1);

House h2=new House(1,2);

House h3=new House(2000,2);

House h4=new House();

House h1=new House(1500,1,1);

57
New cards

Constructor can return a value

True

False

False

58
New cards

The 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;}}

new House(h1);

h1 = new House();

h1.stories=1;

h1.House();

h1 = new House();

59
New cards

A method with a return type of void may still have a return statement in it's code.

True

False

True

60
New cards

What is the output of the following code?

class Counter {

private int seconds=0;

public void addOne() {

seconds++;

}

public void subtractOne() {

seconds--;

}

public int currentCount() {

return seconds;

}

}

class Main {

public static int doStuff(int x, Counter a) {

x++;

a.addOne();

return x+a.currentCount();

}

public static void main(String[] args) {

int x=0;

int y=0;

Counter a = new Counter();

a.addOne();

y=doStuff(x,a);

System.out.println("a "+a.currentCount()+" x "+x+" y "+y);

}

}

a 0 x 0 y 2

a 2 x 0 y 3

a 0 x 0 y 0

a 2 x 1 y 3

a 2 x 0 y 3

61
New cards

What is the output of the following code?

import java.util.ArrayList;

class Main {public static void main(String[] args) {ArrayList myNumbers = new ArrayList();myNumbers.add(10);myNumbers.add(20);myNumbers.add(30);myNumbers.add(40);

int num=0;for(int x : myNumbers) {num+=x;}System.out.println(num);}}

0

40

100

150

100

62
New cards

What is the output of the following code?

import java.util.ArrayList;

class Main {public static void main(String[] args) {ArrayList myNumbers = new ArrayList();

myNumbers.add(10);myNumbers.add(20);myNumbers.add(30);myNumbers.add(40);

System.out.println(myNumbers.get(myNumbers.size()-1));}}

10

20

30

40

40

63
New cards

Given 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 :

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);

}

}

class 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;

}

}

class 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;

}

}

class 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;

}

}

class 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;

}

}

class 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;

}

}

64
New cards

A private attribute in a class is accessible to

Only members of the same class

Only the method that this attribute is defined in

Only the children of this class

Members of the same class and it's children

Only members of the same class

65
New cards

Which line or lines of code below will cause compile errors?

class Parent {

public int x;

}

class Child extends Parent {

public void doStuff() {

System.out.println("I'm a child");

}

}

class Main {

public static void main(String[] args) {

Parent p1 = new Parent();

Child c1 = new Child();

Parent p2 = new Child();

p1.doStuff(); //Line 1

c1.doStuff(); //Line 2

p2.doStuff(); //Line 3

((Child)p2).doStuff(); //Line 4

}

}

Line 1Line 3

Line 1Line 3Line 4

Line 1Line 2Line 3Line 4

Line 1

Line 1Line 3

66
New cards

who getting an A on this bih

hopefully me cause i literally cant fail this plz

67
New cards

What 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();

Thread thread1 = new Thread(t1);

Thread thread2 = new Thread(t2);

Thread thread3 = new Thread(t3);

System.out.println("Let's go!");

thread1.start();

thread2.start();

thread3.start();

System.out.println("Done");

}

}

Let's go!

I'm thread 1

I'm thread 2

I'm thread 3

Done

Let's go!

I'm thread 3

I'm thread 2

I'm thread 1

Done

Let's go!

Done

I'm thread 1

I'm thread 2

I'm thread 3

It's impossible to tell the order the statements will appear in.

It's impossible to tell the order the statements will appear in.

68
New cards

Making a program multithreaded will always ensure it runs faster? T/F

False

69
New cards

What method will contain the body of the thread?

Java

run()

Java

start()

Java

Execute()

Java

start()

run()

70
New cards

What does the following statement do?Thread.sleep(10000);

Causes the current thread to exit

Causes the current thread to pause for 10,000 seconds

Causes the current thread to pause for 10 seconds

Causes the current thread to pause for 1 second

Causes the current thread to pause for 10 seconds

71
New cards

Code written to take advantage of parallel processing will always run faster than code which is not written for parallel processing?

True

False

False

72
New cards

What is the output of the following code?

import java.util.ArrayList;

class Widget {

public String name;

}

class Inventory {

public static ArrayList factoryInventory = new ArrayList();

}

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());

}

}

100

1000

10000

The output will be different each time you run it.

The output will be different each time you run it.

73
New cards

What 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"); }}

Let's go!

I'm thread 1

I'm thread 2

I'm thread 3

Done

Let's go!

I'm thread 3

I'm thread 2

I'm thread 1

Done

Let's go!

Done

It's impossible to tell the order the statements will appear in.

Let's go!

Done

74
New cards

If 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?

Use a simple loop in a single thread, that looks in each of the cells.

Use a multithreaded approach, where you have 10 threads each of which looks in 100,000 cells.

Using a multithreaded approach, where you have 100 threads each of which looks at 10,000 cells.

They would all work.

They would all work

75
New cards

A stack is a data structure that follows the principle of Last In First Out. Whereas a queue is a data structure that follows the principle of First in First Out?

True

False

True

76
New cards

Searching for a value in a Binary Search Tree with N nodes, will take approximately how much time?

O(1)

O(logN)

O(N)

O(N^2)

O(logN)

77
New cards

What is the output of the following code?

class Node {

public char letter;

public Node next;

public Node(char letter) {

this.letter=letter;

next=null;

}

}

class Main {

public static void dostuff(Node head) {

if(head!=null) {

dostuff(head.next);

System.out.print(head.letter);

}

}

public static void main(String[] args) {

Node head = null;

head=new Node('A');

head.next=new Node('B');

head.next.next=new Node('C');

head.next.next.next=new Node('D');

head.next.next.next.next=new Node('E');

dostuff(head);

}

}

ABCDE

EDCBA

A

E

EDCBA

78
New cards

Assuming you have a Queue (myQueue), what is the output of the following operations?

myQueue.enqueue(1);

myQueue.enqueue(2);

myQueue.enqueue(3);

System.out.println(myQueue.dequeue());

System.out.println(myQueue.peek());

System.out.println(myQueue.peek());

123

122

321

322

1

2

2

79
New cards

Assuming you have a linked list that looks like this: ________ next ________ next ________ nexthead --> | data=2 | ------> | data=4 | ------> | data=6 | ------|| ---------- -------- --------

What is the output of the following method assuming myFunc is called and passed head?

class Node {

public int data;

public Node next;

}

public void myFunc(Node current) {

if(current==null) {

return;

}

else {

myFunc(current.next);

System.out.println(current.data);

}

}

246

6

642

2

6

4

2

80
New cards

In the worst case, what is the number of comparisons needed to search a singly-linked list of length N for a given element?

1

LogN

N

N/2

N

81
New cards

In a doubly-linked lists each node contains its value and two pointers:One which points to the next nodeOne which points to the previous node

True

False

True

82
New cards

What is the value of head.next.previous.data in this linked list? ________ next _________ next _________ nexthead --> | data=5 | ------> | data=10 | ------> | data=15 | ------||||-------| |<-------- | | <--------| | previous| | previous | | previous| |---------- --------- ---------

5

10

15

null

5

83
New cards

Which interface uses images/icons to make it easier for the user?

Command Line

Voice Command

Graphical

graphical

84
New cards

In GUI coordinate system, which of the following positions refers to the coordinates (0,0)?

The bottom left corner of the GUI box

The top left corner of the GUI box

The top right corner of the GUI box

The bottom right corner of the GUI box

The top left corner of the GUI box

85
New cards

Pressing a GUI button normally causes an event to occur.

True

False

true

86
New cards

GUI stands for

Geographical User Internet

Graphical User Interface

Graphical Utility Interface

Graphical User Interface

87
New cards

Which of the following is the appropriate GUI (Graphical User Interface) component used to select one from multiple alternatives?

Text Area

Radio Button

Progress Bar

Scroll Bar

Radio button