oop quiz 1

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:57 AM on 8/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

23 Terms

1
New cards

What is the size of an integer variable?

Options:

  • 16 bit

  • 128 bit

  • 32 bit

  • 8 bit

  • 64 bit


32 bit

2
New cards

Does garbage collection guarantee that a program will not run out of memory?

Options:

  • True

  • False


False

3
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

int i=0; boolean t=true; boolean f=false,b; b=(t & ((i++)==0)); b=(f & ((i+=2)>0)); System.out.print(i);

3 (due to bit-wise operators)

4
New cards

Which of the following lines of code will compile without error? (Choose all that apply)

Options:

  • boolean i=true, j=false; if(i && j) System.out.println("OK");

  • boolean b=true; if(b) System.out.println("So true");

  • int i=2, j=2; if(i==1 | j==2) System.out.println("OK");

  • int i=0; if(i) System.out.println("Hello");


a, b, & c

5
New cards

Which of the following are legal identifiers? (Choose all that apply)

Options:

  • _whatavariable

  • variable2

  • 2variable

  • $2

  • #myvar

  • for

  • ___

  • if


_whatavariable, variable2, $2, ___

6
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

boolean x=true; int a; if(x)     a = x ? 1 : 2; else     a = x ? 3: 4; System.out.print(a);

1

7
New cards

What is an applet?

Options:

  • It is a Java program that runs in a Web browser

  • It is a tool

  • It is a run time environment

  • It is a stand-alone Java program

  • It is an IDE


It is a Java program that runs in a Web browser

8
New cards

It is possible to force garbage collection in Java.

Options:

  • True

  • False


False

9
New cards

Primitive variables are stored on stack.

Options:

  • True

  • False


True

10
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

boolean a[] = new boolean[10]; for(int i=5; i<=10 ; i++)     System.out.print(a[i]);

error

11
New cards

When an object is passed as a parameter to a method, a copy of the object is created.

Options:

  • True

  • False


False

12
New cards

Local variables are automatically assigned a default value if not explicitly initialized.

Options:

  • True

  • False


False

13
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

int i=0; boolean t=true; boolean f=false, b; b=(t && ((i++)==0)); b=(f && ((i+=2)>0)); System.out.print(i);

1 (skips evaluating 2nd b, due to false condition)

14
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

int i=5; if(i==5){     int j=10, j+=i; } System.out.println(j);

error, j is not initialized prior to if-condition. After traversing if-condition, j will not exist outside the if-condition, and the print function incurs an error.

15
New cards

Which of the following lines will compile without warning or error?

Options:

  • short s = 900000; char c = 10;

  • float f = 2.5; boolean b = "true";


short s = 900000; char c = 10;

16
New cards

What is the output of the code snippet below?

int temp=1, temp2=0, ans=0, num=5; for(int i=1; i<= num; i++){     ans = temp + temp2;     temp = temp2;     temp2 = ans;     System.out.print(ans + " "); }

1 1 2 3 5

17
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

int i=1; switch(i) {     default: System.out.println("default");     case 0: System.out.println("zero");             break;     case 1: System.out.print("one");     case 2: System.out.print("two"); }

onetwo

18
New cards

A byte can be of what size

Options:

  • -128 to 127

  • (-2 power 8)-1 to 2 power 8 depends on the particular implementation of the Java Virtual Machine -255 to 256


-128 to 127

19
New cards

Which of the following are legal definitions of the main method that can be used to execute a class?

Options:

  • public static void Main(String[] args)

  • public static int main(String args[])

  • public static void main(string args[])

  • Public static void main(String args[])

  • public static void main(String args[])

  • public static void main(String *args)

  • static public void MAIN(String[] args)

  • public void main(String args)


public static void main(String args[])

20
New cards

What is the output of the code snippet below? If there is no output, answer "no output". If there is an error, answer "error".

int x=0, y=1, z; if(x) z=0; else z=1; if(y) z=2; else z=3; System.out.print(z);

error

21
New cards

It is possible to change the contents of a String object.

Options:

  • True

  • False


False

22
New cards

Which of the following is not a keyword in Java?

Options:

  • public

  • private

  • void

  • Boolean

  • static


Boolean

23
New cards

What will happen when you attempt to compile and run this code?

public class Main{     public static void main(String argv){         System.out.println("Hello world");     } }

Options:

  • The code will compile but will complain at run time that main is not correctly defined

  • The code will compile but will complain at run time that no constructor is defined

  • The compiler will complain that main is a reserved word and cannot be used for a class

  • The code will compile and when run will print out "Hello world"


The code will compile but will complain at run time that main is not correctly defi