Question

Hi all, I'm studying for a test for my Java class that coming up on Tuesday,...

Hi all,

I'm studying for a test for my Java class that coming up on Tuesday, and I would love it if someone could look over my answer. Can someone give me some feedback on the wrong one I get wrong? I really need to get it right for the upcoming test.

Here my prep test:

Which one statement is true"

Question1

  1. All objects that are eligible for garbage collection will be removed from the heap by the garbage collector.
  2. Objects with more than one reference will never be garbage collected.
  3. Objects from a class with the finalize() method overridden will never be garbage collected.
  4. Objects instantiated within method local inner classes are placed in the garbage collectible heap.
  5. Once an overridden finalize() method is invoded, there is no way to make that object ineligible for garbage collection.

choices:

1

2

3

4

5

I choose: 1

Question 2

  1. void doSomething() {
  2. X x = doStuff(new X() );
  3. X y = doStuff(x);

28  x = null;

  1. y = null;
  2. }
  3. X doStuff(X x){

32   return doStuff2(x);

  1. }

After which line of code is the object created on line 26 eligible for garbage collection?

  1. After line 28
  2. After line 29
  3. After line 30
  4. The object will not become eligible
  5. It is not possible to know from this code.

choices:

1

2

3

4

5

I choose: 3

Question 3

Which Man class properly represents the relationship "Man has a best

friend who is a Dog"?

  1. class Man extends Dog { }
  2. class Man implements Dog { }
  3. class Man { private BestFriend dog; }
  4. class Man { private Dog bestFriend; }
  5. class Man { private Dog<bestFriend> }
  6. class Man { private BestFriend<dog> }

choices:

1

2

3

4

5

6

I choose: 4

Question 4

Given:

  1. public class Test {
  2. public static void main(String [] args) {
  3. int x =5;
  4. boolean b1 = true;
  5. boolean b2 = false;

16.

17.if((x==4) && !b2)

  1. System.out.print("l ");
  2. System.out.print("2 ");
  3. if ((b2 = true) && b1)
  4. System.out.print("3 ");
  5. }
  6. }

What is the result?

  1. 2
  2. 3
  3. 1 2
  4. 2 3
  5. 1 2 3
  6. Compilation fails.
  7. Au exceptional is thrown at runtime.

choices:

1

2

3

4

5

6

7

I choose: 7

Question 5

When the method pop() is used in the stack. The item is removed from the stack at what location.

choices:

A.Top of Stack

B.Bottom of Stack

C.Need Specific Index

D.Middle of Stack

I choose:B

Question 6

When the method push() is used in the stack. The item is inserted into what position.

choices:

A.Middle of Stack

B.Correct Index Is Needed

C.Top of Stack

D.Bottom of Stack

I choose: B

Question 7

When the method add is used in a queue. The item is added to what location of the queue.

choices:

A.Specific index is required

B.middle of queue

C.head of queue

D.tail of queue

I choose:A

Question 8

When the method remove is used in a queue. The item is removed from what location of the queue.

choices:

A.Specific index is required

B.Middle of queue

C.Head of Queue

D.Tail of Queue

I choose:C

Question 9

Which of the following data structures is considered FILO (FIRST IN LAST OUT):

1. Queue

2. Linked List

3. Tree

4. Stack

choices:

1

2

3

4

I choose: 2

Question 10

String d = "beekeeper";

d.substring(1,7);

d = "w" + d;

d.replace('e', 'y');

System.out.println(d);

What is the result?

  1. wbeebeekeep
  2. wbeekeeper
  3. wbeekeepe
  4. weekeeper
  5. wbyykyyper
  6. Compilation fails
  7. An exception is thrown

choices:

1

2

3

4

5

6

7

I choose: 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) correct option 5

Once an overridden finalize() method is invoded, there is no way to make that object ineligible for garbage collection.

2) after line 28

3) class Man { private Dog bestFriend; }

4 ) 2 3

5) A.Top of Stack

6) C.Top of Stack

7) D.tail of queue

8)  

head of queue

9) 4. Stack

10)wbeekeeper

Add a comment
Know the answer?
Add Answer to:
Hi all, I'm studying for a test for my Java class that coming up on Tuesday,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for...

    Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for a list of size N? Group of answer choices O(1) O(log N) O(N) O(N log N) Flag this Question Question 21 pts Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method...

  • JAVA --Design a class named StackOfStrings that contains: a. A private array elements to store strings...

    JAVA --Design a class named StackOfStrings that contains: a. A private array elements to store strings in the stack b. A private data field size to store the number of strings in the stack c. A constructor to construct an empty stack with a default capacity of 4 d. A constructor to construct an empty stack with a specified capacity e. A method empty() that returns true if the stack is empty f. A method push(String value) that stores value...

  • Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e.,...

    Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e., priority based on the radius of the circle). The application must be menu controlled similar to Project 4 and provide the following. Allow insertion of a "Circle" object/structure in the Priority Queue data structures. Allow display of all elements from Priority Queue data structure by Invoking a method/function "DisplayPriorityQueue" (uses "DeQueue" method). Allow for deletion of the Queue This is what I have so...

  • JAVA LANG PLEASE: I have follwed these below guidelines but when i run my queue test...

    JAVA LANG PLEASE: I have follwed these below guidelines but when i run my queue test it is not executing but my stack is working fine, can you fix it please! MyQueue.java Implement a queue using the MyStack.java implementation as your data structure.  In other words, your instance variable to hold the queue items will be a MyStack class. enqueue(String item): inserts item into the queue dequeue(): returns and deletes the first element in the queue isEmpty(): returns true or false...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • public class PQueue<E extends Comparable<E>> { private E[] elements; private int size; private int head; private...

    public class PQueue<E extends Comparable<E>> { private E[] elements; private int size; private int head; private int tail; Private int count;   } public void enqueue(E item) { if(isFull()){ return; } count++; elements[tail] = item; tail = (tail + 1) % size; } public E dequeue() { if(isEmpty()) return null; int ct = count-1; E cur = elements[head]; int index = 0; for(i=1;ct-->0;i++) { if(cur.compareTo(elements[head+i)%size])<0) cur = elements[(head+i)%size]; index = i; } } return remove((head+index%size); public E remove(int index) { E...

  • can someone please fix this error in the stack file at line 18 ( class Stack2:public...

    can someone please fix this error in the stack file at line 18 ( class Stack2:public Stack { ) this is thew error ----> expected class name before '{' token Queue.h --> #include "Stack.hpp" template <typename ITEM> class Queue { private: ITEM item; Stack <ITEM> * s1= new Stack<ITEM>; Stack <ITEM> * s2= new Stack<ITEM>; public: Queue(){}; bool enqueue (ITEM item); bool dequeue (ITEM &item); bool check = true; ~Queue(); }; //this is the class which contains the functions of...

  • JAVA Lab Create a class called ArrayBasedStack. Declare the following variables: • data: references an array...

    JAVA Lab Create a class called ArrayBasedStack. Declare the following variables: • data: references an array storing elements in the list • topOfStack: an int value representing the location of the stack top in the array • INITIAL_CAPACITY: the default capacity of the stack public class ArrayBasedStack <E> { private E[] data; private int topOfStack; private static final int INITIAL_CAPACITY = 5; } Add a constructor that will initialize the stack with a user-defined initial capacity. The top of the...

  • Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the...

    Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that one item and no items display properly, no matter where front...

  • I just need a java mehod that follows the Javadocs Implented using an arraylist. public class...

    I just need a java mehod that follows the Javadocs Implented using an arraylist. public class WorkAheadQueue<T> implements WorkAheadQueueADT<T> {     private LinearNode<T> front;     private LinearNode<T> back;     private int numNodes;     private ArrayList<LinearNode<T>> frontFive; Removes and returns the element that is at place x in the queue. Precondition: x must be less than 5, x must be less than size * Note: indexing from 0: 0-front element, I =-second element, etc. eparam x the passed in index of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT