0% found this document useful (0 votes)
20 views35 pages

JAVA QB-1,2,3

The document is a Java Question Bank consisting of multiple-choice questions covering various aspects of the Java programming language, including its history, features, syntax, and data types. It includes questions about Java's keywords, control statements, compilation, and execution environment. The questions are organized into units, with Unit-1 focusing on foundational concepts and terminology related to Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views35 pages

JAVA QB-1,2,3

The document is a Java Question Bank consisting of multiple-choice questions covering various aspects of the Java programming language, including its history, features, syntax, and data types. It includes questions about Java's keywords, control statements, compilation, and execution environment. The questions are organized into units, with Unit-1 focusing on foundational concepts and terminology related to Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

<br>

Java Question Bank


Unit-1
1. Who is known as father of Java Programming Language?
(a) M. P Java

(b) Charel Babbage

(c) James Gosling

(d) Blais Pascal

2. Java is a Successor to which programming language?

(a) B

(b) C

(c) C++

(d) D

3. Which of the following is not a Java feature?

(a) Dynamic

(b) Object-oriented
(c) Architecture Neutral
(d) Use of pointers

4. In java control statements break, continue, return, try-catch-finally and assert belongs
to?
(a) Transfer statements

(b) Pause Statement

(c) Selection statements


(d) Loop Statements
5. Java Source Code is compiled into

(a) .obj

(d) Sourcecode
(c).Exe

(d) Bytecode

6. Which of the tool is used to compile java code ?

(a) java

(b) javac

(c) jar
<br>

(d) javadoc

7. Every statement in Java language should end with a?


(a) Comma

(b) Colon
(c) Semicolon

(d) Dot or Period

8. A function in C language is similar to what in Java language?


(a) Method
(b) Member
(c) Variable

(d) None of the above

9. Allmethods and variables in Java language are kept inside a?

(a) main

(b) file

(c) static method


(d) Class or Interface

10. Which one of the following is a java keyword?

(a) switch

(b) while

(c) public

(d) void

11. What is the original name of Java Programming language?

(a) J++

(b) C++

(c) OAK

(d) TEAK

12. Java is a language

(a) Weakly typed

(b) Strongly typed


(c) Moderate typed
(d) None of these

13. Whic company owns Java at present?


<br>

(a) IBM

(b) Microsoft

(c) Oracle

(d) Sun Microsystenis

14. Which laboratory was Java invented or developed in?

(a) Bell Laboratory

(b) Dennis Ritchie Office

(c) Sun Microsystems

(d) Johnson and Johnson

15. Which provides runtime environment for java byte code to be executed?

(a) JDK

(b) JVM

(c) JRE

(d) JAVAC

16. What is byte code in Java?

(a) Name of Java source code file

(b) Block of code written inside a class

(c) Code generated by a Java compiler

(d) Code generated by a Java Virtual Machine

17. Which of the following is used to interpret and execute Java Applet Classes hosted by
HTML.

(a) appletscreen

(b) appletwatcher

(c) appletshow

(d) appletviewer

18. HTML based Java Documentary help can be accessed using

(a) javadoc

(b) javahelp

(c) javamanual
(d) none of these

19. In standalone Java applications, which method is mandatory?

(a) display method


<br>

(b) print method


(c) main method
(d) show method
20. What does JVM stands for?

(a) Java Virtual Machine

(b) Java Virtual Mechanism

(c) Java Variable Machine


(d) None of the above
21. Which one of these lists contains only Java programming language keywords?

(a) byte, break, assert, switch, include


(b) class, if, void, long, Int, continue

(c) try, virtual, throw, final, volatile, transien

(d) goto, instanceof, native, finally, default, throws

22. Single line comment starts with in Java.

(a) /*

(b) /**
(c) //
(d) None of these

23. How to compile java code in command prompt?


(a) java filename

(b) javac filename

(c) java filename.java


(d) javac filename.java

24. Which is a reserved word in the Java programming language?

(a) array

(b) method
(c) subclasses
(d) native

25. The name "JAVA" known to the world as?


(a) Ragi Malt Juice

(b) An Island in Indonesia

(c) A Tea Brand in India


<br>

(d) A Coffee Brand in Africa

26. Java language was originally developed for operating?


(a) TV

(b) TV Set-top box

(c) Embedded System equipment


(d)All the above
27. What is used to find and fix bugs in Java programs.
(a) JDB

(b) JDK

(c) JBM

(d) JRE

28. What is garbage collection in the context of Java?

(a) The JVM cleans output of Java program with error.


(b) Java deletes all unused java files on the system.
(c) Memory used by the object with no reference is automatically reclaimed.
(d) Any unused package in a program automatically gets deleted.

29. The loop keyword of java is

(a) byte

(b) while

(c) float
(d) double

30. What is JVM?

(a) JVM is the confined memory area


(b) Alljava programs run inside JVM memory

(c) JVM provides security to the computer by giving controlled access to Files and Memory
on a computer

(d) All the above

31. What type of Java Programs can be run inside a Java supported Web Browser?

(a) AWT

(b) Applets

(c) Struts
(d) Stand alone
<br>

32. What is the advantage of EXE files?


(a) Run Faster

(b) Efficient

(c) No separate program required to run


(d) All the above

33. Java was publicly released on which date?

(a) 25-05-1995

(b) 29-05-1995

(c) 28-05-1995

(d) 27-05-1995

34. Which one is a template for creating different objects ?


(a) Interface

(b) An Array

(c) A class

(d) Method

35. Which symbol is used to contain the values of automatically initialized arrays?

(a) Braces

(b) Comma

(c) Brackets

(d) Parentheses
36. Java does not define which type modifier?

(a) Auto

(b) Extern

(c) Register

(d) All of these

37. What is Portability offered by Java language?

(a) Java does not actually provide portability

(b) Small code size easy to carry occupying less disk space

(c) Generating suitable Byte Code for each machine by the Compiler
(d) Ability to run the Byte on different machines producing the same behaviour and output

38. What is JIT in Java?


(a) Java In Timer
<br>

(b) Java In Time Thread

(c) Just In Time Compiler

(d) Just ln Time Runnable

39. Choose the correct statement about Java?

(a) JIT Compiler produces Byte Code from Java file.

(b) JIT Compiler assists the actual JAVAC compiler to compile fast
(c) JIT Compilertakes chunks of Byte Code as input and produces Executable code on that
particular machine.
(d) None of the above

40. Java is case sensitive?


(a) True

(b) False

41. What is an Interpreter?

(a) Interpreters are slow to execute

(b) An interpreter converts instructions line by line

(c) An Interpreter converts source code to low-level code

(d) All the above

42. What is a Compiler?

(a) Compilers work fast

(b) A Compiler converts all instructions in one go.

(c) A compiler converts source code to low-level code


(d) Allthe above

43. What happens in the absence of JIT Compiler in Java?

(a) Byte code is produced slowly

(b) Executable Code is produced without portability

(c) Executable Code is produced slowly because of line by line Interpreting


(d) None of the above

44. What is true in Java?

(a) All method names should start with a Lower Case letter.

(b) For all class names the first letter should be in Upper Case
(c) Name of the program file should exactly match the class name.

(d) All of the above


<br>

45. All Java components require names. Names used for classes, variables, and methods are
called?

(a) identifiers

(b) Variables

(c) Java Modifiers

(d) Access Modifiers

46. Choose a correct statement about Java source files.

(a) Java files are human readable


(b) Java files contain Classes with Methods and Variables

(c) Import statements import library Classes into our class

(d) All the above

47. JAR stands for............ss*.

(a) Java Archive

(b) Java Archive Runner

(c) Java Application Runner


(d) None of these

48. What is JRE?

(a) JRE is a java based GUI application.

(b) JRE is an application development framework.

(c) JRE is an implementation of the Java Virtual Machine which executes Java programs.
(d) None of the above
49. What is the Java distribution type used to build Web Apps in Java?
(a) Java SE

(b) Java EE

(c) Java ME

50. What is Ahead of Time Compiler in Java?

(a) Ahead of time compiler compiles java files as and when you type and save.
(b) Ahead of time compiler turns byte code to executable code line by line based on
requirement
(c) Ahead of time compiler is a replacement for JIT compiler to translate all byte code to a
single executable file or code to run the program fast and efficient.
(d) None of the above
<br>

51. Which of the following is smallest integer data type ?


(a) int

(b) byte
(c) short
(d) long

52. How many primitive data types are there in Java?

(a) 6

(b) 7

(c) 8

(d) 9

53. Size of int in java is

(a) 16 bit

(b) 32 bit

(c) 64 bit

(d) Relies on the execution environment


54. The smaller integer type is and its size is bits.

(a) byte, 1

(b) int, 4

(c) short, 8
(d) byte, 8

55. What is the range of short data type in Java?

(a) -128 to 127


(b) -32768 to 32767

(c) -2147483648 to 2147483647


(d) None of the mentioned

56. What is the range of byte data type in Java?


(a) -128 to 127

(b) -32768 to 32767

(c) -2147483648 to 2147483647


(d) None of the mentioned
<br>

57. What does a Data Type in Java refers to?

(a) The place where data is stored

(b) The technique how data is retreived

(c) The type or variety of data being handled for reading and writing
(d) None of the above
58. Which of these literals can be contained in a data type float variable?

(a) 1.7e-308

(b) 3.4e-038

(c) 1.7e+308

(d) 3.4e-050

59. What are the types of data types in Java?


(a) Primitive Data types
(b) Non-primitive Data Types

(c) Both of above


(d) None of these.

60. Which is not a primitive data type?

(a) Boolean

(b) Character

(c) Arrays

(d) Integer

61. Which of the following data types comes under floating data types ?

(a) int

(b) long

(c) byte
(d) double

62. In Java byte, short, int and long all of these are

(a) signed

(b) unsigned

(c) Both of the above


(d) None of these
<br>

63. Size of float and double in Java is


(a) 32 and 64

(b) 64 and 64

(c) 32 and 32
(d) 64 and 32

64. Automatic type conversion in Java takes place when

(a) Two type are compatible and size of destination type is equal of source type.
(b) Two type are compatible and size of destination type is larger than source type.

(c) Two type are compatible and size of destination type is shorter than source type.
(d) Allof the above
65. What is the type of variable 'b' and 'd' in the following Java snippet?
int a[], b;

int[c, d;

(a) 'b' and 'd' are int

(b) 'b' and 'd' are arrays of type int

(c) b' is int variable; 'd' is int array


(d) 'd' is int variable; 'b' is int array

66. Character data type cannot store following value.


(a) Digit

(b) Letter

(c) String

(d) Special Character

67. Default value of variable having boolean data type is


(a) True

(b) False

(c) NULL

(d) garbage

68. An expression involving byte, int, and literal numbers is promoted to which of these?

(a) int
(b) lonf

(c) byte
(d) float
<br>

69. Which of these coding types is used for data type characters in Java?
(a) ASCII

(b) ISO-LATIN-1

(c) UNICODE

(d) None of the mentioned

70. Which of these values can a boolean variable contain?


(a) True

(b) True &False

(c) 0 & 1

(d) 'Any integer value

Unit-2
1. Which of the following can be operands of arithmetic operators?
(a) Characters

(b) Boolean
(c) Numeric

(d) Both Boolean & Characters

2. Which of these can be returned by the operator &?


(a) Integer

(b) Boolean

(c) Character

(d) Integer or Boolean

3. Modulus operato, %, can be applied to which of these?


(a) Integers

(b) Floating point numbers

(c) Both Integers and floating-point numbers.


(d) None of the mentioned

4. An Arithmetic expression in Java involves which Operators or Operations?

(a) Addition (+), Subtraction (-)

(b) Multiplication (*), Division (/)

(c) Modulo Division (%), Increment/Decrement (++/--) Unary Minus (-), Unary Plus (+)

(d) Allthe above


<br>

5. Choose the Compound Assignment Arithmetic Operators in Java below.

(a) +=,-=

(b) *=,I=

(c) \%=

(d) All the above


6. int x = 0 y= 0,z=0;
x =(++x+y.)*z++

What will be the value of "x" after execution ?


(a) 0

(b) 1

(c) 2

(d) -1

7. int ++ a = 100;

System.out.println(+ta);

What will be the output of the above fraction of code ?

(a) 100

(b) Compiler displays error as ++a is not a valid identifier

(c) Displays error as ++a is not enclosed in double quotes in printin statement
(d) None of these

8. What is the output of the following program?


class Numbers{

public static void main(String args[l1){

int a = 20 b= 10

if( (a < b) && (b ++<25))\ System.out.printin("This is any language logic"); } System.out.printin(b); }}

(a) 10

(c) 12

(b) 11

(d) Compilation Error

9. With x=0 which of the following are legal lines of Java code for changing the value of x to 1?

1. x++;

2.
x=X+1
3. x +=1

4. X = 1

(a) 1 \&4
<br>

(b) 3 & 2

(c) 1, 2 &3
(d) 1, 2, 3, &

10. Decrement operator, -, decreases value of variable by what number?

(a) 1

(b) 2

(c) 3

(d) 4

11. Decrement operator, â'n", decreases the value of variable by what number?

(a) 1

(b) 2

(c) 3

(d) 4

12. Which of these statements are incorrect?

(a) Assignment operators run faster than their equivalent long forms.
(b) Assignment operators can be used only with numeric and character data type.
(c) Assignment operators are more efficiently implemented by Java run-time system than their
equivalent long forms.

(d) None of the above

13. What is the output of the below Java code snippet?


inta27;

System.out.printin(a);

(a) -5

(b) 9

(c) 10

(d) Compiler Error

14. Select from among the following character escape code which is not available in Java.

(a) \t
(b) \v

(c) \r
(d) \a
15. When the operator after the variable name, the first assignment of the value of the
++ is placed
variable takes place and then the value of the variable is incremented, this operation is also called
(a) pre-increment
<br>

(b) post-increment

(c) left to right increment


(d) right to left increment

16. When the operators are having the same priority, they are evaluated from expression. in the
order they appear in the
(a) left to right

(b) right to left

(c) any of the above

(d) none of the above

17. Which of these have highest precedence?

(a) ++

(b) *

(c) >>

(d) ()

18. What should be expressionl evaluate to in using ternary operator as in this line?

expression1? expression2: expression3


(a) Integer

(b) Boolean

(c) Floating point numbers

(d) None of the mentioned


19. Which right shift operator preserves the sign of the value?
(a) >>

(b) >>=

(c) <<

(d) <<=

20. Which of these statements are incorrect?

(a) The right shift operator automatically fills the higher order bits with 0

(b) The left shift operator can be used as an alternative to multiplying by 2


(c) The left shift operator, <<, shifts all of the bits in a value to the left specified number of times
(d) The right shift operator, >>, shifts all of the bits in a value to the right specified number of times

21. What is the output of this program?

class operators
{public static void main(String args[])X
int var1=5;
<br>

int var2 =6;

int var3;

var3= ++ var2 * var1/ var2 + var2;


System.out.print(var3);

(a) 10

(b) 11

(c) 12

(d) 56

22. What is the output of this program?

class Main
{public static void main(String args[]) {

int x = 8;
+
System.out.println(++x* 3 +" " x); }}

(a) 24 8

(b) 24 9

(c) 27 8

(d) 27 9

23. Which of these statements is correct?

(a) true and false are non numeric values

(b) true is any non zero value and false is O

(c) true and false are numeric values 1 ando


(d) true and false are numeric values 0 and 1

24. Which of these operators can skip evaluating right hand operand?

(a)!

(b) |

(c) &

(d) &&

25. Which of the following operators can operate on a boolean variable?

(a) ?:

(b) +=

(c) &

(d) \&\&

26. Which of these statements are incorrect?


<br>

(a) Equal to operator has least precedence.


(b) Brackets () have highest precedence.

(c) Division operator, /, has higher precedence than multiplication operator.


(d) Addition operator, +, and subtraction operator have equal precedence.

27. What is the output of this program?

class bool_operator
{public static void main(String args[])
{

boolean a = true;

boolean b= !true:

booleanc =a|b;
booleand =a\& b;

booleanc=d? b: c;
System.out.println (d + 6 ^ 66 + e)

(a) true ture


(b) false false

(c) true false

(d) false true

28. Which of the following loops will execute the body of loop even when condition controlling the
loop is initially false?

(a) for

(b) while

(c) do-while

(d) none of the mentioned

29. Which of these jump statements can skip processing the remainder of the code in its body for a
particular iteration?

(a) return

(b) break

(c) continue
(d) exit

30. Which of this statement is incorrect?

(a) switch statement is mnore efficient than a set of nested ifs

(b) two case constants in the same switch can have identical values
<br>

(c) it is possible to create a nested switch statements


(d) switch statement can only test for equality, whereas if statement can evaluate any type of
boolean expression
31. What is true about a break?

(a) Break stops the execution of entire program

(b) Break halts the execution and forces the control out of the loop
(c) Break forces the control out of the loop and starts the execution of next iteration

(d) Break halts the execution of the loop for certain time frame
32. What will be the output of the program?

class Bitwise
{public static void main(Stringll args)

x =
int 11& 9;
=
int y x^3;

System.out.printin(y | 12); }

}
(a) (0

(b) 7

(c) 8

(d) 14

33. What will be the output of the program?

class Main
{
public static void main(Stringl] args)
{
int x=20; String sup= (x< 15)? "s": (x< 22)? "t": "h";

System.out.printin(sup);

(a) s

(b) t

(c) h

(d)Compilation fails

34. Which of the following will produce an answer that is closest in value to a double, d, while not
being greater than d?

(a) (int)Math.min(d);

(b) (int)Math.abs(d);
<br>

(c) (int)Math.max(d);

(d) (int)Math.floor(d);

35. What will be result of the result of the expression -14%-3

(a) -2

(b) 2

(c) -4

(d) 4

36. What is the output of this program?

class Main
{public static void main(String args[])

double var1= 2
{ + 4;

double var2 = var1/4;


+
System.out.print(var2 "" + var4);
int var32 + 4;

int var4 var3/4;

}}

(a) 01

(b) 10

(c) 1.5 1

(d) 1.5 1.0

37. What will be the output of the program?

class Main
{
public static void main(Stringl] args)

{Main p = new Main(); p.start();

void start()

longl] a1= {3,4,5);

longl] a2 = fix(al);

System.out.print(al [0] + al[1] + al[2] + " ");

System.out.printin(a2[0] + a2[1] + a2[2]);

longl] fix(longl] a3)

}{}

a3[1] = 7;

return a3;
<br>

(a) 12 i2

(b) 15 15

(c) 375375

(d) 345375

38. What is the output of this program?

class Relational_operator
{public static void main(String args[l)
{int var=5;
int var2 = 6:

System.out.print(var1> var2);

(a) 0

(b) 1

(c) TRUE

(d) FALSE

39. What is the output of this program?

class ternary_operator
{public static void main(String args[])
-x
{int x =3 int y = int z; }

z= X> y ?x: y;

System.out.print(z);

(a) 0

(b) 1

(c) 3

(d) -4

40. What is the output of this program?

class Output

{public static void main(String args[])


{int x, y = 1 x= 10 if (x! =10\&X**0==0)

System.out.println(y):

else

System.out.println(++y);
<br>

(a) 1

(b) 2

(c) Unpredictable behavior of program

(d) Runtime error owing to division by zero in if condition

41. A private member of a class is accessible to


(a) in subclass

(b) everywhere
(c) members to the same package

(d) only members of the same class

42. Which concept of Java is a way of converting real world objects in terms of class?

(a) Abstraction

(b) Inheritance

(c) Polymorphism

(d) Encapsulation

43. For Cat and Animal class, correct way of inheritance in java is

(a)class Cat extends Animal


(b) class Animal extends Cat

(c) Both are correct way


(d) None is correct way

44. Which component is used to compile, debug and execute java program?
(a) JDK

(b) JVM

(c) JRE

(d) JIT

45. What is the use of the interpreter?

(a)Can replace JIT


(b) They read high level code and run them

(c) it is the intermediary between JIT and JVM


(d) It converts byte code into machine language

46. Which concept of Java is achieved by combining methods and attribute into a class?

(a) Inheritance

(b) Abstraction

(c) Encapsulation

(d) Polymorphism
<br>

47. What is it called if an object has its own lifecycle and there is no owner?
(a) Aggregation

(b) Composition

(c) Encapsulation

(d) Association

48. JVM Stands for

(a) Java Virtual Memory

(b) Java Virtual Machine

(c) Java Virtual Management


(d) Java Virtual Machanism

49. JRE Stands for

(a) Java Reply Engine

(b) Java Running Engine

(c) Java Runtime Engine

(d) Java Runtime Environment

50. Which of the following is considered as platform independent code ?

(a) Source Code

(b) Compiled File

(c) &
B
BothA

(d) None of these

51. In OOPs in Java, private, public & protected are

(a) Classes

(b) Access Modifiers

(c) Interfaces

(d) Method signature

52. Which component is responsible to run java program?

(a) JDK

(b) JVM

(c) JRE

(d) JIT

53. What is it called where child object gets killed if parent object is killed?

(a) Aggregation

(b)Composition
(c) Encapsulation
<br>

(d) Association

54. Which component is responsible to optimize bytecode to machine code?

(a) JDK

(c) JRE

(b) JVM

(d) JIT

55. In a class, encapsulating an object of another class is called

(a) Inheritance

(b) Encapsulation

(c) Composition

(d) None of these

56. How can we identify if a compilation unit is a class or an interface from a .class file?

(a) Java Source File Header

(b) Extension of the compilation unit

(c) We can't tell the difference between class and interface


(d) The name of the class or interface must be prefixed with the type of unit
57. Which statement is true about java?

(a) Code dependent programming language

(b) Platform dependent programming language

(c) Sequence dependent programming language

(d) Platform independent programming language

58. Which of the below is invalid identifier with the main method?

(a) final

(b) static

(c) private

(d) public

59. Method overriding is combination of inheritance and polymorphism?

(a) True

(b) False

60. Which of the following is not a component of Java Integrated Development Environment (|DE)?

(a) Net Beans

(b) Borland's Jbuilder

(c) Symantec's Visual Café

(d) Microsoft Visual Fox Pro


<br>

Unit-3
1. Which of these packages contain all the collection classes?
(a) java.net

(b) java.awt

(c) java.lang

(d) java.util

2. Which of these classes is not part of Java's collection framework?

(a) Array

(b) Stack

(c) Maps

(d) Queue

3. Which of these interface declares core method that all collections will have?
(a) set
(b) Collection

(c) Comparator

(d) EventListner

4. Suppose that you would like to create an instance of a new Map that has an iteration order that is
the same as the iteration order of an existing instance of a Map. Which concrete implementation of
the Map interface should be used for the new instance?
(a) HashMap

(b) TreeMap
(c) LinkedHashMap

(d) The answer depends on the implermentation of the existing instance.


5. Which class does not override the equals() and hashCode() methods, inheriting them directly from
class Object?

(a) java.lang.String

(b) java.lang. Double

(c) java.lang.Character

() java.lang.StringBuffer
6. Which of these interfaces is not part of the Collection framework in Java?

(a) Set

(c) SortedMap

(b) List

(d) SortedList
<br>

7. Which of the following methods removes all items from a collection?

(a) clear()

(b) reset()

(c) delete()
(d) refresh()

8. What is Collection in Java?

(a) A group of classes

(b) A group of objects

(c) A
group of interfaces

(d) None of the above

9. Which of these interface handle sequences?

(a) Set

(b) List

(c) Comparator

(d) Collection

10. Which of these interface is not a part of Java's collection framework?

(a) Set

(b) List

(c) SortedMap

(d) SortedList

11. Which collection class allows you to grow or shrink its size and provides indexed access to its
elements, but whose methods are not synchronized?
(a) java.util.List

(b) java.util.ArrayList

(c) java.util.HashSet

(d) java.util. LinkedHashSet

that guarantees that no duplicates are stored and all


12. You need to store elements in a collection
elements can be accessed in natural order. Which interface provides that capability?
(a) java.util.List

(b) java.util.Coliection

(c) java.util.Map

(d) java.util.Set
<br>

13. Which of these interfaces is not part of the collection framework in Java?

(a) Set

(b) List

(c) Group
(d) Collection

14. Which interface does not allow duplicates elements?

(a) Set

(b) List

(c) Map

(d) All the answers are true


15. Which of these interface must contain a unique element?

(a) Set

(c) Array

(b) List

(d) Collection

16. Which of these is Basic interface that all other interface inherits?

(a) Set

(c) Array

(b) List

(d) Collection

17. Which of these is an incorrect form of using method max() to obtain maximum element?

(a) max(List c)

(b) max(Collection c)

(c) max(Comparator comp)

(d) max(Collection c. Comparator comp)

18. Which of these methods sets every element of a List to a specified object?

(a) set()

(b) fil()

(c) add()

(d) Complete()

19. Which interface does java.util.Hashtable implement?

(a) Java.util.List

(b) Java.util.Map

(c) Java.util.Collection
<br>

(d) Java.util.HashTable

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

(a) java.util.ArrayList

(b) java.util.HashMap

(c) java.util.TreeMap

(d) java.util.LinkedHashMap

21. Which collection class allows you to access its elements by associating a key with an element's
value, and provides synchronization?
(a) java.util.TreeSet

(b) java.util.Hashtable
(c) java.util.SortedMap

(d) java.util.TreeMap

22. Which is valid declaration of a float?

(a) float f= "1";

(b) floatf= 1.0d;


(c) float f = 1F;
(d) float f= 1.0;
23. Which of these collection classes has the ability to scale Jynamically?

(a) Array

(b) Arrays

(c) ArrayList

(d) All the answers are true


24. Which of these methods can randomize all elements in a list?

(a) rand()

(b) randomize()

(c) shuffle()

(d) ambigous()

25. Which of these methods can convert an object into a List?

(a) CopyList()

(b)SetList()
(c) ConvertList()

(d) singletonList()
<br>

26. Which of these is true about unmodifiable Collection() method?

(a) unmodifiableCollection() method is available only for List and Set.

(b) unmodifiableCollection() is defined in Collection class.

(c) unmodifiableCollection() returns a collection that cannot be modified.


(d) None of the mentioned.

27. A Java reference is compafable to in C language.

(a) Enum

(b) Pointer

(c) Structure

(d) None

28. is the superclass to all Java classes either user-defined or built-in.

(a) Class

(c) NULL

(b) Object

(d) Superclass

29. List, Set and Queue

(a) extends Collection.

(b) implements

(c) both of the above

(d) none of the above

30. Which of the following is legacy class in java?

(a) Vector

(b) Arraylist

(c) Hashtable

(d) OnlyA &C

31. String in Java is a?

(a) class

(b)object
(c) variable

(d) character array


32. Which of these method of String class is used to obtain character at specified index?

(a) char()

(b) Charat()

(c) charat()
<br>

(d) charAt()

33. What is the stored in the object obj in following lines of Java code? bOx obj;

(a) NULL

(b)Garbage
(c) Any arbitrary pointer

(d) Memory address of allocated memory of object

34. which statement is true?

(a) class Test' will not compile.

(b) class Test2 will not compile.

(c) The Test1 hashCode() method is less efficient than the Test2 hashCode() method.

(d) The Test1 hash Code() method is more efficient than the Test2 hashCode() method.
35. HashMap allows

(a) null key

(b) null values

(c) All the answers are true


(d) None of the above

36. Which of these is static variable defined in Collections?

(a) EMPTY_MAP

(b) EMPTY LIST

(c) EMPTY_SET

(d) Allof the mentioned

37. What is Collection in Java?

(a) A group of classes

(b) A group of interfaces

(c) A group of objects

(d) None of the mentioned


38. Iterator and Listlterator can traverse over

(a) sets

(b) maps

(c) lists

(d) Allof the above

39. Which of these is true about unmodifiable Collection() method?

(a) unmodifiable Collection() is defined in Collection class

(b) unmodifiable Collection() method is available only for List and Set
<br>

(c) unmodifiable Collection() returns a collection that cannot be modified


(d) none of the mentioned
40. Which statement is true for the class java.util.HashSet?

(a) The elements in the collection are ordered.


(b) The collection is guaranteed to be immutable.
(c) The elements in the collection are guaranteed to be unique.
(d) The elements in the collection are accessed using a unique key.

41. What is the output of the below Java program with two classes?

//Testing1.java
publicclass Example {} public class Testing1( public static void main(Stringl[] args) {

ystem.out.printin ("Hello Boss.!"); }}

(a) No Output

(b) Hello Boss.!

(c) Compiler error

(d) None of the above

42. What is the output of the below Java program using toString() method? class College { public
String toString() return "College Object";

class Testing18
{public
static void main(String[] args)
{College col = new College();

System.out.println (" PrintingObject=" + col);

(a) Printing Object=

(b) Printing Object=null

(c) Printing Object=College Object

(d) Compiler error

43. What is the output of the below Java program?

class Cricket

int runs;

}
class Testing19
{
public static void main(Stringl] args)

Cricket c1 = new Cricket();


<br>

=
cl.runs 250;

Cricket c2;

c2 = cl;

c2.runs=300;
System.out.printin("Runs= " + cl.runs);

(a) Runs= 0

(b) Runs= 250

(c) Runs= 300

(d) Compiler error

44. What is the output of the below Java program?

class WordPress

int posts;

class Testing20

public static void main(Stringll args)


{

WordPress wpl = new WordPress();


= 25;
wpl.posts

WordPress wp2 =
wp1;
wpl = null:

System.out.println("Posts=" + wp2.posts);
(a) Posts=NULL

(b) Posts=0

(c) Posts=25

(d) Runtime exception occurs

45. Which implementation of Iterator can traverse a collection back and forth?
(a) Iterator

(b) Listiterator

(c) Setlterator
(d) Maplterator

46. What will be the output of the following Java program?


<br>

import java.util.*;

class Array
{public static void main(String args[])
{

int array[l =
new int [5];

for (int i= 5; i> 0; i-)

array[5-i] =i;

Arrays.fil(array, 1, 4, 8);
= 0;
for (int i
i< 5; i++)

System.out.print(array[i]);

(a) 12885

(b) 12845

(c) 58881

(d) 54881

47. List, Set and OQueue Collection.

(a) inherit

(b) implement

(c) Both A and B are true

(d) None of the above

48. What will be the output of the following Java program?

class string_clasS

public static void main(String args[)


{

= LIKE JAVA";
String obj "|

System.out.println(obj.length(0);
}

(a) 9

(b) 10

(c) 11

(d) 12

49. The Comparable interface contains which called?

(a) toCompare

(b) compare
<br>

(c) compareTo

(d) compare With

50. Deque and Queue are derived from:

(a) List

(b) Collection

(c) AbstractList

(d) AbstractCollection

51. Which are also known as inner classes?

(a) Nested class

(b) Static nested class


(c) Non-static nested class
(d) None of the above

52. Which is true about an anonymous inner class?

(a) It can extend exactly one class and can implement multiple interfaces.

(b) It can extend exactly one class or implement exactly one interface.

(c) It can extend exactly one class and implement exactly one interface.

(d) It can implement multiple interfaces regardless of whether it also extends a class.

53. Which is true about a method-local inner class?

(a) It can be marked public.

(b) It can be marked static.

(c) It must be marked final.

(d) It can be marked abstract.

54. class Boo

Boo(String s) {)

Boo() )

{{ Bar()

} class Bar extends Boo


Bar(String s) (super(s);}

void zoo()

|/ insert code here

which one create an anonymous inner class from within class Bar?
(a) Boof f= new Bar() ();

(b) Booff= new Boo(24) ();


(c) Bar f= new Boo(String s) (0;
<br>

(d) Boof f= new Boo. Bar(String s) );


55. Which statement is true about a static nested class?

(a) It must extend the enclosing class.


(b) It's variables and methods must be static.

(c) It does not have access to nonstatic members of the enclosing class.
(d) You must have a reference to an instance of the enclosing class in order to instantiate it.

56. Which constructs an anonymous inner class instance?

(a) Runnable r = new Runnable() {}:

(b) Runnable r= new Runnable(public void run() {});

(c) Runnabier r = new Runnable (public void run()};


(d) System.out.println(new Runnable() (public void run() {});

57. The inner class can access private members of the outer class

(a) True

(b) False

58. What will be the output of the program? public class HorseTest
{
publicstatic void main (String[] args) { class Horse { public String name; /* Line 7*1 public
Horse(String s) }

name= S;
}/* class Horse ends */

Object obj = new Horse("Zippo"); /* Line 13 */Horseh (Horse) obj; /* Line 14 */

System.out.println(h.name);

}}/ class HorseTest ends */


(a) It prints "Zippo".

(b) An exception occurs at runtime at line 10.


(c) Compilation fails because of an error on line 7.
(d) Compilation fails because of an error on line 13.

59. What will be the output of the program?

public class TestObj


{
publicstatic void main (Stringl] args)

{Object o = new Object() /* Line 5 */

{
public boolean equals(Object obj)

return true;
{

}}/* Line 11 */

System.out.println(o.equals("Fred"));
<br>

(a) It prints "true",.

(b) It prints "Fred".

(c) Compilation fails

(d) An exception occurs at runtime.

60. What will be the output of the program?

public abstract class AbstractTest


{public int getNum()

{return 45;

public abstract class Bar


}

{
public int getNum()

{return 38;
public static void main (String[) args)

AbstractTest t = new AbstractTest()


{
AbstractTest.Bar f = t.new Bar()public int getNum() {return 57;
public int getNum() { return 22; } }; {

}}}System.out.printin(f.getNum() +" " + t.getNum(0);


(a) An exception occurs at runtime.

(b) 45 57

(c) 57 22

(d) 45 38

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy