Java Programming Final - FT, Java Programming Final - MT

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

Which of the following is not a primitive type? A) String B) char C) int D) float

A) String

Which statement is false? A) The methods for primitive types correspond to the methods for the corresponding type-wrapper classes. B) Each primitive type has a corresponding type-wrapper class. C) The type-wrapper classes enable you to manipulate primitive-type values as objects. D) Type-wrapper classes are final, so you cannot extend them.

A) The methods for primitive types correspond to the methods for the corresponding type-wrapper classes.

Which of the following is the escape character? A) \ B) \n C) " D) *

A) \

String objects are immutable. This means they ________. A) cannot be changed B) cannot be deleted C) must be initialized D) None of the above

A) cannot be changed

Another problem related to indefinite postponement is called ________. This occurs when a waiting thread (let's call this thread1) cannot proceed because it's waiting (either directly or indirectly) for another thread (let's call this thread2) to proceed, while simultaneously thread2 cannot proceed because it's waiting (either directly or indirectly) for thread1 to proceed. The two threads are waiting for each other, so the actions that would enable each thread to continue execution can never occur. A) deadlock B) impass C) stalemate D) standoff

A) deadlock

Class Arrays provides method ________ for comparing arrays to determine whether they have the same contents. A) equals B) compares C) equal D) compare

A) equals

A(n) ________ indicates a problem that occurs while a program executes. A) exception B) syntax error C) omitted import D) missing semicolon

A) exception

Any field declared with keyword ________ is constant. A) final B) const C) constant D) static

A) final

Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)? A) public abstract int method1(); B) public int nonfinal method1(); C) public int abstract method1(); D) public int method1();

A) public abstract int method1();

The length of a string can be determined by ________. A) the String method length() B) the String method strlen() C) the String instance variable length D) All of the above.

A) the String method length()

Polymorphism allows for specifics to be dealt with during ________. A) compilation B) execution C) debugging D) programming

B) execution

Given the following declaration: StringBuilder buf = new StringBuilder(); What is the capacity of buf? A) 0 B) 10 C) 16 D) 20

C) 16

What is the size in bits of an int? A) 8 B) 16 C) 32 D) 64

C) 32

Consider the array: s[0] = 7 s[1] = 0 s[2] = -12 s[3] = 9 s[4] = 10 s[5] = 3 s[6] = 6 The value of s[s[6] - s[5]] is ________. A) 0 B) 3 C) 9 D) 10

C) 9

Each of the following is a relational or equality operator except ________. A) <= B) == C) =! D) >

C) =!

Which is the output of the following statements? System.out.print("Hello "); System.out.println("World"); A) Hello World B) World Hello C) Hello World D) HelloWorld

C) Hello World

Let's say a Book class has a public instance variable called pages. What will be the output of the following piece of code? Book[] books = new Book[10]; books[0].pages = 98; System.out.println(books[0].pages); A) 10 B) 98 C) It will throw a null pointer exception D) There is a compilation error in link books[0].pages = 98;

C) It will throw a null pointer exception

Consider you have gathered a list of skills from many of your friends. You put them in an array A = {"java", "c#", "c", "java", "c", "python", "c#", "c"}. Now you want to know the unique list of skills from this list. What data structure would you use to get the unique list of skills in this array? A) ArrayList B) Map C) Set D) LinkedList

C) Set

What would be the output of the following code segment? 1 for(int i=0; i<3; i++) 2 System.out.println( i + " "); 3 System.out.println(i); A) 0 1 2 B) 0 1 2 3 C) 1 2 3 D) It will be a compiler error for line 3

D) It will be a compiler error for line 3

What would be the output for the following block of code? int sum = 0; for(int i=0; i<3; i++) { sum = sum + i; } System.out.println("i = " + i + " sum = " + sum); A) i = 2 sum = 3 B) i = 3 sum = 3 C) i = 3 sum = 4 D) It will be a compiler error in the System.out.println line E) It will be a compiler error in for loop line

D) It will be a compiler error in the System.out.println line

In array items, which expression below accesses the value at row 3 and column 4? A) items[3].[4] B) items[3[4]] C) items[3, 4] D) items[3][4]

D) items[3][4]

Which command compiles the Java source code file Welcome.java? A) javac Welcome.java B) compile Welcome.java C) cd Welcome.java D) java Welcome.java

A) javac Welcome.java

Which is a correct static method call of Math class method sqrt? A) math.sqrt(900); B) Math.sqrt(900); C) sqrt(900); D) Math math = new Math(); math.sqrt(900);

B) Math.sqrt(900);

Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo(int aVal, int bVal) { ​ a = aVal; ​ b = bVal; } public abstract int calculate(); } Any concrete subclass that extends class Foo ________. A) must implement a method called calculate B) will not be able to access the instance variable a C) Both A and B. D) Neither A nor B.

C) Both A and B.

Which statement is false? A) A ListIterator accesses the elements of a List. B) ArrayLists execute faster than Vectors because they are not thread safe. C) A LinkedList is a linked list implementation of a List. D) Class ArrayList is a fixed-size array.

D) Class ArrayList is a fixed-size array.

What do the following statements do? double[] array; array = new double[14]; A) Create a double array containing 15 elements. B) Create a double array containing 13 elements. C) Declare but do not create a double array. D) Create a double array containing 14 elements.

D) Create a double array containing 14 elements.

You want to store the number of traffic violations against the driving license numbers. The driving license numbers are unique. For each driving license, the number of violations are need to be stored. What data structure should you use in this kind of scenario to add a new record or lookup the number of violations for a given driving license number? A) Stack B) Set C) Multidimensional array D) HashMap E) ArrayList

D) HashMap

You have an array Arr with the values {1,2,3,4}. What would be the output of the following line? System.out.println(Arr[4]); A) 3 B) 4 C) 5 D) It will throw an exception

D) It will throw an exception

Which of the following promotions of primitive types is not allowed to occur? A) short to long. B) char to int. C) int to double. D) double to float.

D) double to float.

Which keyword is used to specify that a class will define the methods of an interface? A) uses B) defines C) extends D) implements

D) implements

What is the result value of c at the end of the following code segment? int c = 8; c++; ++c; c %= 5; A) 0 B) 1 C) 3 D) None of the above

A) 0

What is the value of result after the following Java statements execute (assume all variables are of type int)? a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; A) 119 B) 127 C) 59 D) 51

A) 119

What would be the output for the following code segment? int a = 1; System.out.print(a++); System.out.print(++a); System.out.print(a); A) 133 B) 233 C) 123 D) 223

A) 133

Which statement creates a random value from the sequence 2, 5, 8, 11 and 14? Suppose randomNumbers is a SecureRandom object. A) 2 + 3 * randomNumbers.nextInt(5); B) 2 + 5 * randomNumbers.nextInt(3); C) 3 + 2 * randomNumbers.nextInt(5); D) 5 + 3 * randomNumbers.nextInt(2);

A) 2 + 3 * randomNumbers.nextInt(5);

A Java class can have which of the following methods? A. void foo(int a) B. void foo(int a, int b) C. void foo(double a) D. void foo(double a, double b) E. void foo(int b) A) A, B, C, D. B) A, C, D, E. C) A, B, D, E. D) All of the above.

A) A, B, C, D.

Which of the following statements about arrays are true? A. An array is a group of variables containing values that all have the same type. B. Elements are located by index. C. The length of an array c is determined by the expression .length();. D. The zeroth element of array c is specified by c[0]. A) A, B, D. B) A, C, D. C) A, B, C, D. D) C, D.

A) A, B, D.

Which of the following statements is false? A) Each class can be used only once to build many objects. B) Just as the notion of interchangeable parts was crucial to the Industrial Revolution, reusable classes are crucial to the software revolution that has been spurred by object technology. C) Avoid reinventing the wheel-use existing high-quality pieces wherever possible. This software reuse is a key benefit of object-oriented programming. D) Reuse helps you build more reliable and effective systems, because existing classes and components often have undergone extensive testing, debugging and performance tuning.

A) Each class can be used only once to build many objects.

Which of the following statements is false? A) If a method does not return a value, the return-value-type in the method declaration can be omitted. B) Forgetting to return a value from a method that should return a value is a compilation error. C) Redeclaring a method parameter as a local variable in the method's body is a compilation error. D) Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.

A) If a method does not return a value, the return-value-type in the method declaration can be omitted.

Which of the following is false? A) If you have an ArrayList variable al, you can get the size of the al by al.length . B) You can add a new item to the end of an ArrayList with its add method. C) You can get an item from a specified index in an ArrayList with its get method. D) The size of an ArrayList can be determined via its size method.

A) If you have an ArrayList variable al, you can get the size of the al by al.length .

A(n) ________ allows a program to walk through the collection and remove elements from the collection. A) Iterator B) Queue C) Set D) List

A) Iterator

You have created a generic method with the following syntax. Which of the following option is not true? public static <E> void printArray( E[] inputArray ) { System.out.printf("Inside generic print "); for(E element : inputArray) { System.out.printf("%s ", element); } System.out.println(); } A) One should put <T> instead of using <E> in the above code B) I can pass any type of array to this generic method C) I could also get the same feature by creating multiple overloaded methods D) If intArray is an Integer array, this line will print all the value of inArray: printArray(intArray);

A) One should put <T> instead of using <E> in the above code

class NewThread implements Runnable { String name; Thread t; NewThread(String threadname) { name = threadname; t = new Thread(this, name); t.start(); } public void run() { try { System.out.println("Inside run method"); Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("In the catch"); } } public void start(){ System.out.println("Inside start method"); } } Consider the above class. If you write the following statement in your main method, what would be the output? NewThread ob1 = new NewThread("One"); A) One B) Inside run method C) Inside start method D) In the catch

B) Inside run method

Which method call converts the value in variable stringVariable to an integer? A) Integer.toInt(stringVariable) B) Integer.parseInt(stringVariable) C) Convert.toInt(stringVariable) D) Convert.parseInt(stringVariable)

B) Integer.parseInt(stringVariable)

Consider the class below: public class Test { public static void main(String[] args) { ​ int[] a = {99, 22, 11, 3, 11, 55, 44, 88, 2, -3}; ​ int result = 0; ​ for (int i = 0; i < a.length; i++) { ​ if (a[i] > 30) { ​ result += a[i]; ​ } ​ } ​ System.out.printf("Result is: %d%n", result); } } The output of this Java program will be ________. A) Result is: 332 B) Result is: 286 C) Result is: 280 D) Result is: 154

B) Result is: 286

Suppose variable gender contains MALE and age equals 60, how is the expression (gender == FEMALE) && (age >= 65) evaluated? A) The condition (age >= 65) is evaluated first and the evaluation stops immediately. B) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately. C) Both conditions are evaluated, from left to right. D) Both conditions are evaluated, from right to left.

B) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.

Map method ________ is used to determine whether a map contains a mapping for the specified key. A) hasMapping B) containsKey C) containsMapping D) hasKey

B) containsKey

Which command executes the Java class file Welcome.class? A) run Welcome.class B) java Welcome C) java Welcome.class D) java welcome

B) java Welcome

Which of the following is not a valid Java identifier? A) m_x B) my Value C) $_AAA1 D) width

B) my Value

Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int, long, float and double. All other types are ________ types. A) source B) reference C) static D) declared

B) reference

Which of the following statements is false? A) An object's attributes are specified as part of the object's class B) Each bank-account object knows the balance in the account it represents, but not the balances of the other accounts in the bank. C) Attributes are specified by the class's methods. of money in the account. D) A bank-account object would likely have a balance attribute that represents the amount

C) Attributes are specified by the class's methods.

Consider the statements below: String a = "JAVA: "; String b = "How to "; String c = "Program"; Which of the statements below will create the String r1 = "JAVA: How to Program"? A) String r1 = c.concat(b.concat(a)); B) String r1 = c.concat(c.concat(b)); C) String r1 = a.concat(b.concat(c)); D) String r1 = b.concat(c.concat(a));

C) String r1 = a.concat(b.concat(c));

Consider the code segment below. Which of the following statements is false? int[] g; g = new int[23]; A) The first statement declares an array reference. B) The second statement creates the array. C) The value of g[3] is -1. D) g is a reference to an array of integers.

C) The value of g[3] is -1.

In a class containing methods with the same name, the methods are distinguished by ________. A) types of arguments B) number of arguments C) return type D) A and B E) A and C

D) A and B

Which of the following methods are overloaded with respect to one another? public int max (int a, int b) { ... } public double max (double a, double b) { ... } public int max (int a, int b, int c) { ... } public double max (double a, double b, double c) { ... } A) A, B and C are overloaded. B) A and B are overloaded; C and D are overloaded. C) A and C are overloaded; B and D are overloaded. D) All four methods are overloaded.

D) All four methods are overloaded.

Which of the following statements is true? A) A program might call a bank-account object's deposit method to increase the account's balance. B) You send messages to an object; each message is implemented as a method call that tells a method of the object to perform its task. C) When you drive a car, pressing its gas pedal sends a message to the car to perform a task-that is, to go faster. D) All of the above statements are true.

D) All of the above statements are true.

A static method can ________. A) be called using the class name and a dot (.) B) manipulate only static fields in the same class directly C) call only other static methods of the same class directly D) All of the above.

D) All of the above.

Which statement is true? A) With integer division, any fractional part of the calculation is lost. B) Dividing two integers results in integer division. C) With integer division, any fractional part of the calculation is truncated. D) All of the above.

D) All of the above.

Consider the following two Java code segments: Segment 1: int i = 0; while (i < 20) { i++; System.out.println(i); } Segment 2: for (int i = 0; i <= 20; i++) { System.out.println(i); } A) The scope of the control variable i is different for the two segments. B) The output from these segments is not the same. C) Neither A nor B is true. D) Both A and B are true.

D) Both A and B are true.

Consider the following piece of code and choose the output : abstract class Base { abstract void fun(); } class Derived extends Base { void fun() { System.out.println("Derived fun() called"); } void fun2() { System.out.println("Derived fun() called"); } } class Main { public static void main(String args[]) { Base b1 = new Base(); Base b2 = new Derived(); b2.fun(); } } A) Both line 8 and 9 should be compiler error. B) It will show a compiler error for line 9 C) Derived fun() called D) It will show a compiler error for line 8

D) It will show a compiler error for line 8

Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A and C is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class B. Which of the following statements is true of class C? A) If method originalMethod is not overridden in class C but is called by an object of class C, an error occurs. B) Method originalMethod cannot be overridden in class C-once it has been implemented in concrete class B, it is implicitly final. C) Method originalMethod must be overridden in class C, or a compilation error will occur. D) None of them.

D) None of them.

Which of the following statements is false? A) A factory method is a public static method that creates and initializes an object of a specified type (possibly of the same class), then returns a reference to it. B) Another common use of private constructors is to force client code to use so-called "factory methods" to create objects. C) You can implement single tone design pattern using private constructor D) You cannot prevent client code from creating objects of a class.

D) You cannot prevent client code from creating objects of a class.

Which of the following promotions of primitive types is not allowed to occur? A) char to int. B) short to long. C) int to double. D) double to float.

D) double to float.

The statement s1.equalsIgnoreCase(s4) is equivalent to which of the following? A) s1.regionMatches(true, s4, 0, s4.length); B) s1.regionMatches(0, s4, 0, s4.length); C) s1.regionMatches(0, s4, 0, s4.length()); D) s1.regionMatches(true, 0, s4, 0, s4.length());

D) s1.regionMatches(true, 0, s4, 0, s4.length());

Which class is not a type-wrapper class? A) Int B) Character C) Byte D) Double

A) Int

Which of the following represents the output of the following code segment? abstract class Base { Base() { System.out.println("Base Constructor Called"); } abstract void fun(); } class Derived extends Base { Derived() { System.out.println("Derived Constructor Called");} void fun() { System.out.println("Derived fun() called"); } } class MainClass { public static void main(String args[]) { Derived d = new Derived(); } } A) Print "Base Constructor Called" then print "Derived Constructor Called" B) It will shown an error as the super constructor need to be called by using super() C) Print "Derived Constructor Called" then print "Base Constructor Called" D) We must write @override above the fun() method in Derived class.

A) Print "Base Constructor Called" then print "Derived Constructor Called"

You have installed JDK in your computer. However, when you write a command "javac TestClass.java" to compile the file, it shows an error: "javac is not recognized as an internal or external command". What could be the most common reason? A) You have not set the path environment variable properly B) It is a compiler error in your code C) It is an exception in your code D) You need to reinstall JDK

A) You have not set the path environment variable properly

If the desired Object is not found, binarySearch returns ________. A) a negative value B) zero C) a positive value D) an ObjectNotFoundError

A) a negative value

A class that implements an interface but does not declare all of the interface's methods must be declared ________. A) abstract B) public C) interface D) final

A) abstract

Consider the following piece of code StringBuilder buffer = new StringBuilder(5); buffer.append("All your unhappiness hurts me. Isn't it sufficient to prove that I love you all?"); Which of the following is true about the buffer variable after executing the above two lines of code? A) buffer will contain the full string appended in the line buffer.append(); B) buffer will contain only first 5 character of the string from the second line. C) The append line is a compiler error as buffer's capacity is only 5 and it cannot hold the full string. D) The value of buffer will be empty even we have called the append method.

A) buffer will contain the full string appended in the line buffer.append();

Which of the following lines is false about final Classes and final methods: A) final methods are static B) final classes prevent further inheritance C) You cannot override final methods. D) All the options are true

A) final methods are static

Every object in Java knows its own class and can access this information through method ________. A) getClass B) getInformation C) objectInformation D) objectClass

A) getClass

Iterator method ________ determines whether the Collection contains more elements. A) hasNext B) containsNext C) contains D) next

A) hasNext

For String c = "Hello. She sells sea shells"; The Java statements int i = c.indexOf("ll"); int j = c.lastIndexOf("Java"); will result in ________. A) i = 2 and j = -1 B) i = 2 and j = 0 C) i = 24 and j = -1 D) i = 24 and j = 0

A) i = 2 and j = -1

Which of the following performs an unboxing conversion? Assume x refers to an Integer object. A) int y = x; B) Integer y = x; C) Both of them. D) None of them.

A) int y = x;

In an expression containing values of the types int and double, the ________ values are ________ to ________ values for use in the expression. A) int, promoted, double B) int, demoted, double C) double, promoted, int D) double, demoted, int

A) int, promoted, double

The .class extension on a file means that the file ________. A) is produced by the Java compiler (javac) B) contains java source code C) contains HTML D) None of the above.

A) is produced by the Java compiler (javac)

The main method executes in the ________ thread of execution. A) main B) starting C) local D) None of the above.

A) main

In a producer/consumer relationship, the ________ portion of an application generates data and stores it in a shared object, and the ________ portion of an application reads data from the shared object. A) producer, consumer B) outputter, inputter C) consumer, producer D) None of the above.

A) producer, consumer

When a higher-priority thread enters the ready state, the operating system generally preempts the currently running thread (an operation known as preemptive scheduling). Depending on the operating system, a steady influx of higher-priority threads could postpone-possibly indefinitely-the execution of lower-priority threads. such indefinite postponement is sometimes referred to more colorfully as ________. A) starvation B) famine C) malnourishment D) fasting

A) starvation

Class Number is ________ of both Integer and Double. A) the superclass B) composed C) the subclass D) a descendent

A) the superclass

Consider the following Java statements: int x = 9; double y = 5.3; result = calculateValue(x, y); Which of the following statements is false? A) x and y are parameters B) x and y are arguments C) A method is called with its name and parentheses. D) Copies of x and y are passed to the method calculateValue.

A) x and y are parameters

Which statement is false? A) A List is a Collection. B) A List cannot contain duplicate elements. C) A List is sometimes called a sequence D) Lists use zero-based indices.

B) A List cannot contain duplicate elements.

Which of the following is not possible? A) A class that implements two interfaces B) A class that inherits from two classes. C) A class that inherits from one class, and implements an interface. D) All of the above are possible.

B) A class that inherits from two classes.

Which edition of Java is geared toward developing large-scale, distributed networking applications and web-based applications? A) Industrial Edition B) Enterprise Edition C) Micro Edition D) Standard Edition

B) Enterprise Edition

It's recommended that you do not explicitly create and use Thread objects to implement concurrency, but rather use the ________ interface. A) ExecutorService B) Executor C) Runnable D) Concurrent

B) Executor

Which of the following statements is false? A) In Java SE 8, an interface may declare default methods-that is, public methods with concrete implementations that specify how an operation should be performed. B) When a class implements an interface, the class receives the interface's default concrete implementations if it does not override them. C) When you enhance an existing interface with default methods-any class that implemented the original interface will break. D) With default methods, you can declare common method implementations in interfaces (rather than abstract classes), which gives you more flexibility in designing your classes.

C) When you enhance an existing interface with default methods-any class that implemented the original interface will break.

Floating-point literals are of type ________ by default. A) decimal B) float C) double D) real

C) double

What will be the output of the following code segment? String s1, output; s1 = "hello"; s1.toUpperCase(); System.out.println(s1); A) s1 B) Hello C) hello D) HELLO

C) hello

A new class of objects can be created conveniently by ________; the new class (called the ________) starts with the characteristics of an existing class (called the ________), possibly customizing them and adding unique characteristics of its own. A) inheritance, superclass, subclass B) composition, superclass, subclass C) inheritance, subclass, superclass D) composition, subclass, superclass

C) inheritance, subclass, superclass

The command ________ executes a Java application. A) cmd B) run C) java D) javac

C) java

The classes and interfaces which comprise the collections framework are members of package ________. A) java.collections B) java.collection C) java.util D) javax.swing

C) java.util

A new thread begins its life cycle by transitioning to the ________ state. A) runnable B) waiting C) new D) terminated

C) new

Which of the following is a Scanner method for inputting an integer value? A) nextInteger B) int C) nextInt D) integer

C) nextInt

Which of the followings cannot be a constructor of Bike class? (Choose all that applies) A) public Bike(double a, int b) B) public Bike() C) public double Bike(double a, int b) D) public int Bike()

C) public double Bike(double a, int b) D) public int Bike()

When an object is concatenated with a String, ________. A) a compilation error occurs B) a runtime error occurs C) the object's toString method is implicitly called to obtain the String representation of the object D) the object's class name is concatenated with the String

C) the object's toString method is implicitly called to obtain the String representation of the object

You have an Account object called acc that has a balance variable. You have a multi thread programming that uses the acc object. If multiple thread access this acc object at the same time and deduct the balance variable, there is a risk that the balance variable will become inconsistent. How would you prevent the acc object to be modified by multiple thread at the same time and make it thread safe? A) using join method B) using run method C) using synchronized block D) using start method

C) using synchronized block


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

Chapter 3: Describing Data Visually

View Set

CST Microbiology and the Process of Infection

View Set

Ch 39: Management of Patients with Oral and Esophageal Disorders

View Set

Chapter 23 - The Digestive System

View Set

HIPAA Privacy Rule, HIPAA, HIPAA Compliance Education review

View Set

Reconstruction - Black Codes, Jim Crow & KKK

View Set