Final Exam COP 3337 Questions with
Correct Answers
A class can implement more than one interface?
a) True
b) False - Answer-a) True
Which of the following is true about the interfaces in java.
1. An interface can contain following type of members.
...public, static, final fields (i.e., constants)
...default and static methods with bodies
2. An instance of interface can be created.
3. A class can implement multiple interfaces
4. Many classes can implement the same interface - Answer-a) 1,3 and 4
Which of the following can not be a member of an interface?
a) Non Static Data Members
b) Static Methods
c) Constructors
d) All in the answer list - Answer-d) All in the answer list
When a class implements an interface, it need to ____ all the interfaces methods?
a) Overload
b) Override - Answer-b) Override
Which of the following is true about anonymous inner classes?
a. You can create 'n' number of objects to anonymous inner classes
b. Anonymous inner classes will not have the name
c. You can instantiate anonymous inner classes only once - Answer-c) Both B and c are
true
What is the ArrayList nums if it is initially [5,3,1] and the following code is executed?
Nums.add(6);
Nums.add(0,4); Nums.remove(1); - Answer-d) [4,3,1,6]
Which of the following points is/are true about linked list data structure when it is
compared with array
a. It is easy to insert and delete elements in linked list
b. Random access is not allowed in a typical implementation of Linked Lists
,c. The size of array has to be pre-decided, linked lists can change their size any time
d. All are true - Answer-d) All are true
Which statement is true about a static nested class?
a) It must extend the enclosing class
b) You must have a reference to an instance of the enclosing class in order to
instantiate it
c) Its variables and methods must be static
d) It does not have access to nonstatic members of the enclosing class - Answer-d) It
does not have access to nonstatic members of the enclosing class
Match the definitions with their suitable terms
a) The last item that is added is the first item that is removed (LIFO)
b) The first item that is added is the first term that is removed (FIFO)
c) Can use a circular array for its implementation
d) An ordered set of data elements, each containing a link to its successor (and
sometimes its
predecessor)
e) _______, increases the list by 100% when another element is added if the list is full
f) It is an inner class without a name and for which only a single object is created -
Answer-a) stack
b) queue
c) Queue
d) Linked List
e) Vector List
f) Anonymous Class
Predict the output of the following code
public class Quiz4 {public static int fun(int n) {
if (n==4)else return 2*fun(n+1);
}
public static void main(String[] args) { System.out.println(fun(2));}
} - Answer-b) 16
Consider the following recursive function fun(x,y). What is the value of fun(4,3)
public static int fun(int x, int y) {
if (x==0)
return y;
return y;
return fun(x-1, x+y);
} - Answer-b) 13
What does the following function print for n=25?
public static void fun(int n) {
if (n==0) return;
Which line will cause an error
public interface A { final int k=8; private int m;
String fun(char s);
} - Answer-d) Line 2
which statement is correct?
public interface L { public void go();
}
class M {public void go() {
//Line 1
if (x==0) return y;
return fun(x - 1, x + y);
12) What does the following function print for n=25?
public static void fun(int n) {
if (n==0) return;
System.out.print(n%2); fun(n/2);
//Line 2 public void aMethod(); //Line 3
System.out.println("GO!");
//Line 4
}}
class N extends M implements L{}
public class A{public static void main(String[] args) {
N a = new N();
a.go(); }
} - Answer-c) this will print GO!
will this compile?
interface A{int n = 111;
}
class B implements A{ void inc() {
n++; }
} - Answer-a) True
Given the following code, what is the result?
public class Quiz4 {static class Char { //line 1
char c;public Char(char c) {
this.c = c; public void print() {
System.out.print(c);
}}
private static void typeText(Char c) { c.print();
}
public static void main(String[] args) { typeText(new Char('A'));
typeText(new Char('B'){
a) compile error as class N does not override go method
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller lectknancy. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $18.49. You're not tied to anything after your purchase.