oop2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

"Arraylist" class

Which class or interface defines the wait(), notify(),and notifyAll() methods?

"Object" class

What is the value of myCount.count displayed? public class Test { public static void main(String[ ] args){ Count myCount = new Count(); int times = 0; for (int i=0; i<100; i++)increment(myCount, times); System.out.println( ʺmyCount.count = ʺ + myCount.count); System.out.println(ʺtimes = ʺ+ times); }public static void increment(Count c, int times){ c.count++; times++; } } class Count { int count;Count(int C){ count = c; } Count() { count = 1; }}

100

Which is true about a method-local inner class?

A method-local inner class is a class defined inside a method of another class. It has access to the local variables of the enclosing method, but these variables must be final or effectively final.

Which is true about an anonymous inner class?

An anonymous inner class is a type of method-local inner class that has no name and is defined and instantiated in a single expression. It can be used to create objects that implement interfaces or extend classes without creating a separate class.

Which is valid declaration of a float?

Float myfloat (example)

Which statement is true about a static nested class?

It does not have access to nonstatic members of the enclosing class.

Which interface does java.util.Hashtable implement?

Java.util.map

Which interface provides the capability to store objects using a key-value pair?

Java.util.map

Which method must be defined by a class implementing the java.lang.Runnable interface?

Run()

What is the output? public class Wow { public static void go(short n) { System.out.println("short"); } public static void go(Short n) { System.out.println("SHORT"); } public static void go(Long n) { System.out.println(" LONG"); } public static void main(String [] args) { Short y = 6; int z = 7; go(y); go(z); }}

SHORT LONG

What will the result for following code? public class Yikes { public static void go(Long n) { System.out.println("Long "); } public static void go(Short n) { System.out.println("Short "); } public static void go(int n) { System.out.println("int "); } public static void main(String [] args) { short y = 6; long z = 7; go(y); go(z); }}

Short Long

Which method registers a thread in a thread scheduler?

Start()

Which is a valid declarations of a String?

String str (example)

Which statement is true for the following code? public class Plant { private String name; public Plant(String name) { this.name = name; } public String getName() { return name; }}public class Tree extends Plant { public void growFruit() { } public void dropLeaves() { }}

The code will compile without changes.

What is the output? interface TestA { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new TestA() { public String toString() { return "test"; } }); } }

The output of the code will be the string representation of the anonymous inner class object created by implementing the TestA interface and overriding its toString() method, which is "test".

Which statement is true public class CreditCard { private String cardID; private Integer limit; public String ownerName; public void setCardInformation(String cardID, String ownerName, Integer limit) { this.cardID = cardID; this.ownerName = ownerName; this.limit = limit; }}

The ownerName variable breaks encapsulation.

What is the printout of the following switch statement? char ch = ʹbʹ; switch (ch) { case ʹaʹ: System.out.print(ch); case ʹbʹ: System.out.print(ch); case ʹcʹ: System.out.print(ch); case ʹdʹ: System.out.print(ch);}

bb

What is the output of the following code: public class Test { public static void main(String[ ] args){ Object o1 = new Object(); Object o2 = new Object(); System.out.print((o1 == o2) + ʺ ʺ + (o1.equals(o2))); } }

false false

What will be the output? public class Base { public static final String FOO = "foo"; public static void main(String[] args) { Base b = new Base(); Sub s=newSub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); }} class Sub extends Base { public static final String FOO="bar"; }

foo bar foo bar foo

What is the numerical range of a char?

from 0 to 65,535 (2^16 - 1)

Which one of these lists contains only programming language keywords?

goto, instanceof, native, finally, default, throws

Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

java.util.LinkedHashMap

Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

java.util.concurrent.ConcurrentHashMap

What is the number of iterations in the following loop: for (int i = 1; i < n; i++){ // iteration }

n - 1

When invoking a method with an object argument, a ... is passed.

reference to object

What is the output of the following code? public class Test { public static void main(String[ ] args){ String s1 = ʺWelcome to Java!ʺ; String s2 = s1; if (s1 == s2) System.out.println(ʺs1 and s2 reference to the same String objectʺ); else System.out.println(ʺs1 and s2 reference to different String objectsʺ); }}

s1 and s2 reference to the same String object.

Which cannot directly cause a thread to stop executing?

thread.stop()

What is the printout of the following code: double x = 5.5; int y = (int)x; System.out.println(ʺx is ʺ + x + ʺ and y is ʺ + y);

x is 5.5 and y is 5


संबंधित स्टडी सेट्स

Final Exam - New Jersey Life and Health

View Set

Nutrition Chapter 6 : Proteins, Amino Acids, and Vegetarian Diet

View Set

CH 26 Fluid, Electrolyte & Acid-Base Balance

View Set

AP Euro Chapter 19: A Revolution in Politics: The Era of the French Revolution and Napoleon

View Set

HCAL ll Lewis Chapter 15 - Cancer

View Set