0% found this document useful (0 votes)
192 views92 pages

java ôn tập

Uploaded by

Emilina Katyusha
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)
192 views92 pages

java ôn tập

Uploaded by

Emilina Katyusha
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/ 92

Trinh Quang Hien (K14 DN)

Dashboard  Computing Fundamentals  Campus Da Nang 


PRO192 - Object-Oriented Programming (with Java)  PRO192 - FALL 2019  Information for Class SE1403 
Trial Mini Quiz 3

Started on Wednesday, 27 November 2019, 6:10 PM


State Finished
Completed on Wednesday, 27 November 2019, 9:39 PM
Time taken 3 hours 28 mins
Marks 66.00/200.00
Grade 3.30 out of 10.00 (33%)

Question 1 Which of the following is NOT TRUE for JVM ?


Not answered
Select one:
Marked out of 1.00
a. JVM is a middle layer connecting Java App. to Host Operating System

b. JVM converts Byte Code to Machine Code


c. JVM converts Source Code to Byte Code

The correct answer is: JVM converts Source Code to Byte Code

Question 2 Which of the following is NOT TRUE for JVM ?


Not answered
Select one:
Marked out of 1.00
a. JVM converts Source Code to Byte Code
b. JVM converts Byte Code to Machine Code

c. JVM is a middle layer connecting Java App. to Host Operating System

The correct answer is: JVM converts Source Code to Byte Code

/
Question 3 The ___ is entry point of Java program.
Not answered
Select one:
Marked out of 1.00
a. instance method

b. static method

c. main method
d. class method

The correct answer is: main method

Question 4 The ___ is entry point of Java program.


Not answered
Select one:
Marked out of 1.00
a. static method
b. main method

c. class method
d. instance method

The correct answer is: main method

Question 5 A ___ is the hardware or software environment in which a program runs.


Not answered
Select one:
Marked out of 1.00
a. JVM
b. JRE

c. platform
d. javac tool

The correct answer is: platform

/
Question 6 A ___ is the hardware or software environment in which a program runs.
Not answered
Select one:
Marked out of 1.00
a. JVM

b. javac tool

c. platform
d. JRE

The correct answer is: platform

Question 7 The Java platform has two components:____,_____.


Not answered
Select one:
Marked out of 1.00
a. java compiler, java
b. JVM, Java Run-time Environment

c. JVM, the java application programming interface (API)


d. JVM, java compiler

The correct answer is: JVM, the java application programming interface (API)

Question 8 The Java platform has two components:____,_____.


Not answered
Select one:
Marked out of 1.00
a. JVM, java compiler
b. JVM, the java application programming interface (API)

c. java compiler, java

d. JVM, Java Run-time Environment

The correct answer is: JVM, the java application programming interface (API)

/
Question 9 Which of the following concept does not belong to object oriented programming features?
Not answered
Select one:
Marked out of 1.00
a. Inheritance

b. Polymorphism

c. Encapsulation
d. Cross-platform

The correct answer is: Cross-platform

Question 10 Which is a valid keyword in Java?


Not answered
Select one:
Marked out of 1.00
a. Integer
b. Float

c. include
d. interface

The correct answer is: interface

Question 11 The meaning of platform independent is ___?


Not answered
Select one:
Marked out of 1.00
a. the execution of the program is restricted by the type of OS environment provided.

b. not easy to execute on any system after compilation.

c. write once, run anywhere

The correct answer is: write once, run anywhere

/
Question 12 Choose a right statement about javac tool.
Not answered
Select one:
Marked out of 1.00
a. javac tool is used to run JVM

b. The compiler converts the high-level into a format understood by the machines.
c. javac tool is used to run java application.

d. javac tool compiles class and interface definitions into bytecode class files.

The correct answer is: javac tool compiles class and interface definitions into bytecode class
files.

Question 13 A java source code is a file with the file extension is …….
Not answered
Select one:
Marked out of 1.00
a. .java

b. .class

c. .jar

d. .rar

The correct answer is: .java

Question 14 A java source code is a file with the file extension is …….
Not answered
Select one:
Marked out of 1.00
a. .class

b. .rar

c. .jar

d. .java

The correct answer is: .java

/
Question 15 A Java source code will be compiled to the file with file extension is ……
Not answered
Select one:
Marked out of 1.00
a. .bat

b. .java

c. .class

d. .exe

The correct answer is: .class

Question 16 A Java source code will be compiled to the file with file extension is ……
Not answered
Select one:
Marked out of 1.00
a. .bat

b. .java

c. .class

d. .exe

The correct answer is: .class

Question 17 Which of the following is the best description about polymorphism ?


Not answered
Select one:
Marked out of 1.00
a. It is the ability for many messages/data to be processed in one way

b. It is the ability for a message/data to be processed in only one form

c. It is the ability for a message/data to be processed in more than one form.

The correct answer is: It is the ability for a message/data to be processed in more than one
form.

/
Question 18 Which of the following is the best description about polymorphism ?
Not answered
Select one:
Marked out of 1.00
a. It is the ability for a message/data to be processed in more than one form.

b. It is the ability for many messages/data to be processed in one way

c. It is the ability for a message/data to be processed in only one form

The correct answer is: It is the ability for a message/data to be processed in more than one
form.

Question 19 What is the difference between a class and an object?


Not answered
Select one:
Marked out of 1.00
a. A class is a blueprint to make an object

b. a class is only like to an object

c. An object is a blueprint to make a class

d. none of the others

The correct answer is: A class is a blueprint to make an object

Question 20 What is the difference between a class and an object?


Not answered
Select one:
Marked out of 1.00
a. A class is a blueprint to make an object

b. a class is only like to an object


c. An object is a blueprint to make a class

d. none of the others

The correct answer is: A class is a blueprint to make an object

/
Question 21 Choose a primitive datatype in Java.
Not answered
Select one:
Marked out of 1.00
a. String

b. Date

c. char

d. Integer

The correct answer is: char

Question 22 Choose a datatype that is not a reference datatype.


Not answered
Select one:
Marked out of 1.00
a. Class

b. Interface

c. Array

d. boolean

The correct answer is: boolean

Question 23 assume that all lib files are imported. What is the output of the code?
Not answered public static void main(String[] args){
Marked out of 1.00 Date a=new Date();
boolean result=a instanceof Date
System.out.print("a is instance of :"+result);
}

Select one:
a. a is instance of : false

b. a is instance of : Calendar

c. a is instance of : true

d. a is instance of : Object

The correct answer is: a is instance of : true

/
Question 24 consider the code:
Not answered public static void main(String[] args) {

Marked out of 1.00 int[][] arr = { {1,2,3}, {4,5,6,6}, {6,7,8}};


int [] copy={9,10,11,12};
arr[2]=copy;
System.out.println(arr[2][2]);
}
What is the output of above code?

Select one:
a. 8

b. 9
c. 6

d. 11

The correct answer is: 11

Question 25 consider the code:


Not answered public static void main(String[] args) {

Marked out of 1.00 int[][] arr = { {1,2,3}, {4,5,6,6}, {6,7,8}};


int [] copy={9,10,11,12};
arr[2]=copy;
System.out.println(arr[2][2]);
}
What is the output of above code?

Select one:
a. 8

b. 6

c. 9

d. 11

The correct answer is: 11

/
Question 26 Basic primitive types may include_____
Not answered
Select one:
Marked out of 1.00
a. Scanner, System, Math, File

b. Character, Integer, Long, Float, Double, Boolean

c. char, int, long, float, double, boolean

The correct answer is: char, int, long, float, double, boolean

Question 27 Which statement is used to store a big long number, e.g. 5 billion?
Not answered
Select one:
Marked out of 1.00
a. int n = 5000000000;

b. int n = 5b;

c. long n = 5000000000;

d. long n = 5_000_000_000L;

The correct answer is: long n = 5_000_000_000L;

Question 28 Which of the following belongs to the type of character?


Not answered
Select one:
Marked out of 1.00
a. ‘c’

b. “c”

c. “char”

d. ‘char’

The correct answer is: ‘c’

/
Question 29 Which of the following belongs to the type of character?
Not answered
Select one:
Marked out of 1.00
a. “char”

b. ‘char’

c. ‘c’

d. “c”

The correct answer is: ‘c’

Question 30 Which statement is used to store a hexa number, e.g. FACE?


Not answered
Select one:
Marked out of 1.00
a. int n = 0FACE;

b. int n = FACE;

c. int = hexFACE;

d. int n = 0xFACE;

The correct answer is: int n = 0xFACE;

Question 31 Suppose that a and b are single dimensional arrays of integers, index1 and index2 are valid
Not answered indexes. Study the following statements:

Marked out of 1.00 (1) a[index1]= b[index2] ;


(2) a=b;

Select one:
a. Both (1) and (2) are not accepted.

b. (1) is accepted only.

c. Both (1) and (2) are accepted.

d. (2) is accepted only.

The correct answer is: Both (1) and (2) are accepted.

/
Question 32 Select a correct Java declaration.
Not answered
Select one:
Marked out of 1.00
a. int $myInt;

b. int !cash;
c. int 3money;

d. int interface;

The correct answer is: int $myInt;

Question 33 Which of the following can be used to access the second element of an array named
Not answered arrOne?

Marked out of 1.00


Select one:
a. arrOne[0]
b. arrOne[3]

c. arrOne[2]
d. arrOne[1]

The correct answer is: arrOne[1]

Question 34 Which of the following declaration is NOT correct?


Not answered
Select one:
Marked out of 1.00
a. private int i;
b. public protected String myString;

c. public class MyMoney { }

d. class ParserNum {}

The correct answer is: public protected String myString;

/
Question 35 Choose the valid array declaration in java.
Not answered
Select one:
Marked out of 1.00
a. char[3] myArray;

b. char myArray[3]=['a','b','c'];

c. char[] myArray;
d. char myArray={'a','b','c'};

e. char myArray[3];

The correct answer is: char[] myArray;

Question 36 Which of following operator is used to allocate memory to array variable in Java?
Not answered
Select one:
Marked out of 1.00
a. new malloc

b. calloc

c. new

d. malloc

The correct answer is: new

Question 37 State of a software object is ____


Not answered
Select one:
Marked out of 1.00
a. class declaration which the object belongs to

b. memory block was allocated


c. values in object's fields

The correct answer is: values in object's fields

/
Question 38 State of a software object is ____
Not answered
Select one:
Marked out of 1.00
a. memory block was allocated

b. values in object's fields


c. class declaration which the object belongs to

The correct answer is: values in object's fields

Question 39 Behaviors of an object are implemented via _____


Not answered
Select one:
Marked out of 1.00
a. fields

b. properties
c. methods

The correct answer is: methods

Question 40 Behaviors of an object are implemented via _____


Not answered
Select one:
Marked out of 1.00
a. methods

b. properties
c. fields

The correct answer is: methods

/
Question 41 The keyword ____ is used to declare a subclass.
Not answered
Select one:
Marked out of 1.00
a. extension

b. extend
c. extends
d. expands

The correct answer is: extends

Question 42 The keyword ____ is used to declare a subclass.


Not answered
Select one:
Marked out of 1.00
a. extension

b. expands

c. extend
d. extends

The correct answer is: extends

Question 43 _____ is a way to group related classes in Java and it is called as a namespace also.
Not answered
Select one:
Marked out of 1.00
a. software
b. folder

c. file
d. package

The correct answer is: package

/
Question 44 _____ of OOP supports ability to hide information.
Not answered
Select one:
Marked out of 1.00
a. polymorphism

b. inheritance

c. encapsulation
d. grouping

The correct answer is: encapsulation

Question 45 The modifier ____ is a way to hide information of a class from outside world.
Not answered
Select one:
Marked out of 1.00
a. protected
b. public

c. default

d. private

The correct answer is: private

Question 46 Common access modifiers are


Not answered
Select one:
Marked out of 1.00
a. public, private, protected, default

b. public, final, static, protected, default

c. public, final, static, protected, default, private

The correct answer is: public, private, protected, default

/
Question 47 Common access modifiers are
Not answered
Select one:
Marked out of 1.00
a. public, final, static, protected, default, private

b. public, final, static, protected, default


c. public, private, protected, default

The correct answer is: public, private, protected, default

Question 48 Assume that all library files are imported. Study the following code:
Not answered public class Test {

Marked out of 1.00 int x;


public static final int N=30;
static {
System.out.print("A");
System.out.print(N);
}
Test (int xx) {
x=xx;
}
static {
System.out.print("B");
}
public static void main (String[] args){
Test obj = new Test(5);
}
}
Result of this program is ____

Select one:
a. A30B

b. AB30
c. Compile-time error

d. B30A

The correct answer is: A30B

/
Question 49 Assume that all lib files are imported. Study the following code:
Not answered public class Test {
Marked out of 1.00 void f() {
System.out.print(1);
}
}
class Test2 extends Test {
void f() {
System.out.print(2);
}
}
class Program {
public static void main (String[] args) {
Test obj = new Test2();
obj.f();
}
}
What is it's result?

Select one:
a. 2

b. Compile-time error
c. 1
d. 12

e. 21

The correct answer is: 2

/
Question 50 Assume that all lib files are imported. Study the following Java code:
Not answered public final class Test {
Marked out of 1.00 void f() {
System.out.print(1);
}
}
class Test2 extends Test {
void f() {
System.out.print(2);
}
}
class Program {
public static void main (String[] args){
Test obj = new Test2();
obj.f();
}
}
What is it's result?

Select one:
a. 1

b. Compile-time error

c. 2
d. 3

The correct answer is: Compile-time error

/
Question 51 Assume that all lib files are imported. Study the following Java code:
Not answered public final class Test {
Marked out of 1.00 void f() {
System.out.print(1);
}
}
class Test2 extends Test {
void f() {
System.out.print(2);
}
}
class Program {
public static void main (String[] args){
Test obj = new Test2();
obj.f();
}
}
What is it's result?

Select one:
a. 2

b. 1
c. Compile-time error

d. 3

The correct answer is: Compile-time error

/
Question 52 Study the following code:
Not answered public class Test {
Marked out of 1.00 int x= 5;
int y=2;
public static void main (String[] args){
Test obj;
obj.x=10;
obj.y=20;
System.out.println(obj.x + obj.y);
}
}
What is output?

Select one:
a. Error

b. 7
c. 30

d. 90

The correct answer is: Error

Question 53 Hiding internal data from the outside world, and accessing it only through publicly exposed
Not answered methods is known as data .........

Marked out of 1.00


Select one:
a. specification
b. encapsulation

c. aggregation
d. grouping

The correct answer is: encapsulation

/
Question 54 Choose a proper option to fill up blanks.
Not answered statement 1: A software object's state is stored in ____.
Marked out of 1.00 Statement 2: A software object's behavior is exposed through ______.

Select one:
a. methods, fields

b. fields, background
c. functions, methods

d. fields, methods

The correct answer is: fields, methods

Question 55 Choose a proper option to fill up blanks.


Not answered statement 1: A software object's state is stored in ____.
Marked out of 1.00 Statement 2: A software object's behavior is exposed through ______.

Select one:
a. functions, methods
b. fields, methods

c. fields, background
d. methods, fields

The correct answer is: fields, methods

/
Question 56 What is the output from the following code?
Not answered class NumberHolder {
Marked out of 1.00 public int anInt;
public float aFloat;
}
public class Main {
public static void main(String[] args) {
NumberHolder aNumberHolder;
aNumberHolder.anInt = 1;
aNumberHolder.aFloat = 2.3f;
System.out.print(aNumberHolder.anInt);
System.out.print(aNumberHolder.aFloat);
}
}

Select one:
a. 12.3f

b. Error
c. 12.3
d. 3.3

The correct answer is: Error

/
Question 57 What is the output from the following code?
Not answered class NumberHolder {
Marked out of 1.00 public int anInt;
public float aFloat;
}
public class Main {
public static void main(String[] args) {
NumberHolder aNumberHolder;
aNumberHolder.anInt = 1;
aNumberHolder.aFloat = 2.3f;
System.out.print(aNumberHolder.anInt);
System.out.print(aNumberHolder.aFloat);
}
}

Select one:
a. 12.3

b. Error
c. 12.3f
d. 3.3

The correct answer is: Error

Question 58 Object-oriented programming allows classes to ____ commonly used state and behavior
Not answered from other classes. In Java, the ____ keyword is used to declare a subclass of another
class.
Marked out of 1.00

Select one:
a. have, extend
b. use, extends

c. inherit, extends
d. use, implements

The correct answer is: inherit, extends

/
Question 59 Object-oriented programming allows classes to ____ commonly used state and behavior
Not answered from other classes. In Java, the ____ keyword is used to declare a subclass of another
class.
Marked out of 1.00

Select one:
a. use, extends

b. inherit, extends

c. use, implements
d. have, extend

The correct answer is: inherit, extends

Question 60 What does the static heap contain?


Not answered
Select one:
Marked out of 1.00
a. class declarations
b. objects

c. local variable
d. object reference

The correct answer is: class declarations

/
Question 61 Given the following class definition
Not answered public class Dog {
Marked out of 1.00 private String name;
//constructor…

public void setName(String newName) {


//????
}
}
Which of the following statement is suitable for the implementation of setName() method?

Select one:
a. newName = name;

b. this.name = newName;
c. name == newName;
d. name = this.newName;

The correct answer is: this.name = newName;

Question 62 What happens if you don't put a constructor in a class definition?


Not answered
Select one:
Marked out of 1.00
a. The class creates its own without any arguments.
b. You get an error message.

c. The class creates its own with arguments for every method.
d. The class creates its own with arguments for every variable

The correct answer is: The class creates its own without any arguments.

/
Question 63 What happens if you don't put a constructor in a class definition?
Not answered
Select one:
Marked out of 1.00
a. You get an error message.

b. The class creates its own with arguments for every method.
c. The class creates its own without any arguments.
d. The class creates its own with arguments for every variable

The correct answer is: The class creates its own without any arguments.

/
Question 64 What is the output from the following code
Not answered class Test {
Marked out of 1.00 public static int x = 7;
public int y = 3;
}
public class Main {
public static void main(String[] args) {
Test a = new Test();
Test b = new Test();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.print(a.y);
System.out.print(b.y);
System.out.print(a.x);
System.out.print(b.x);
}
}

Select one:
a. 3377

b. 7373
c. 5612

d. 7733

e. 5622

The correct answer is: 5622

/
Question 65 Assume that all classes are the same package.
Not answered public class Staff {
Marked out of 1.00 int id=100;
private void m(){ System.out.println(id); }
}
public class Manager extends Staff {
int bonus=10;
void m() { System.out.println(id +"-"+ bonus); }
[1] public static void main(String[] args){
[2] Staff A=new Manager();
[3] A.m(); }
}
Choose a right statement about the code.

Select one:
a. can not access the property id from class Manager

b. can not access the method at row [3]

c. 100-10
d. syntax error at row [2]

The correct answer is: can not access the method at row [3]

/
Question 66 public class A {
Not answered void m() { System.out.println( toString()) ;}
Marked out of 1.00 }
public class B {

void m() { System.out.println( "This is class B :" + toString()) ;}

public static void main( String []args) {

A x=new B();
((B)x).m();

Choose a right statement about the code.

Select one:
a. you must use the try ...catch when convert datatype.

b. because "m" is the overrided method, so you do not convert any more.
c. class B can not be converted to class A.
d. can not access class B from the main method

The correct answer is: class B can not be converted to class A.

/
Question 67 public class A {
Not answered void m() { System.out.println( toString()) ;}
Marked out of 1.00 }
public class B {

void m() { System.out.println( "This is class B :" + toString()) ;}

public static void main( String []args) {

A x=new B();
((B)x).m();

Choose a right statement about the code.

Select one:
a. can not access class B from the main method

b. because "m" is the overrided method, so you do not convert any more.
c. you must use the try ...catch when convert datatype.

d. class B can not be converted to class A.

The correct answer is: class B can not be converted to class A.

Question 68 Where to store an object of a class?


Not answered
Select one:
Marked out of 1.00
a. File System (in disk)

b. HEAP segment

c. STACK segment

The correct answer is: HEAP segment

/
Question 69 Declare a method by using _______ will prevent it from overriding
Not answered
Select one:
Marked out of 1.00
a. const

b. static

c. final
d. public

The correct answer is: final

Question 70 what method is implemented in super class and can not be overridden in derived classes?
Not answered
Select one:
Marked out of 1.00
a. private method
b. default method

c. protected method
d. final method

The correct answer is: final method

Question 71 Which of the following keyword is not an access modifier?


Not answered
Select one:
Marked out of 1.00
a. final

b. private

c. public
d. protected

The correct answer is: final

/
Question 72 Which modifiers on instance variables will announce to the compiler that these variables are
Not answered not stored as part of its object's persistent state?

Marked out of 1.00


Select one:
a. public

b. volatile
c. synchronized
d. native

e. transient

The correct answer is: transient

Question 73 Assume that all needed classes were created.


Not answered Consider the following code statements

Marked out of 1.00 public static void main(String[] args){


Dog d1 = new Dog();
d1.setName(“Milu”);
Dog d2 = d1;
d2.setName(“Misa”);
}
After executing all, what is the name of the dog d1 and d2 (in this order)?

Select one:
a. Misa, Milu

b. Milu, Milu

c. Misa, Misa

d. Milu, Misa

The correct answer is: Misa, Misa

/
Question 74 If you want to write some functions in a class with same name but their argument lists are
Not answered different. So, what Java feature will you use?

Marked out of 1.00


Select one:
a. Encapsulation

b. Function overloading
c. Function overriding

The correct answer is: Function overloading

Question 75 What does the default modifier mean?


Not answered
Select one:
Marked out of 1.00
a. It can provide access to any class in the different packages which is a super class.
b. It means as the private modifier.

c. It means as the protected modifier.

d. It provides access to any class in the same package.

The correct answer is: It provides access to any class in the same package.

Question 76 What does the default modifier mean?


Not answered
Select one:
Marked out of 1.00
a. It provides access to any class in the same package.
b. It means as the protected modifier.
c. It can provide access to any class in the different packages which is a super class.

d. It means as the private modifier.

The correct answer is: It provides access to any class in the same package.

/
Question 77 Suppose that A, B, C are classes in which B is a subclass of A. Study the following
Not answered declarations:
A objA;
Marked out of 1.00
B objB;
C objC;
Select a valid statement.

Select one:
a. objB=objC;

b. objB=objA;
c. objA=objC;
d. objC=objB;

e. objA=objB;
f. objC=objA;

The correct answer is: objA=objB;

Question 78 The re-use code ability is a result of the …… in OOP.


Not answered
Select one:
Marked out of 1.00
a. aggregation
b. inheritance

c. polymorphism

d. encapsulation

The correct answer is: inheritance

/
Question 79 Real-world objects share two characteristics. They all have state and behavior. Software
Not answered objects are conceptually similar to real-world objects. they too consist of state and related
behavior. A software object stores its state in _____ and exposes its behavior through
Marked out of 1.00
______.

Select one:
a. packages, interfaces

b. fields, methods
c. methods, fields
d. classes, objects

The correct answer is: fields, methods

Question 80 Consider the following class declaration: public class Test{ }


Not answered What is the prototype of the default constructor?
Marked out of 1.00
Select one:
a. public Test(void)
b. public Test( )

c. public static Test()


d. public void Test( )

The correct answer is: public Test( )

Question 81 Which statement is used to invoke the constructor of the super class from the sub class?
Not answered
Select one:
Marked out of 1.00
a. this()
b. super()

c. extends()
d. parent()

The correct answer is: super()

/
Question 82 Given the following class definition
Not answered public class Cat {
Marked out of 1.00 //declare fields here…
public Cat() {
}
//more code here…
}
Which of the following is correct to create an object?

Select one:
a. Cat c = new Cat;

b. Cat c = Cat();
c. Cat c = Cat().new;
d. Cat c = new Cat();

The correct answer is: Cat c = new Cat();

Question 83 A subclass inherits all of the __ and ____ members of its parent.
Not answered
Select one:
Marked out of 1.00
a. public, protected
b. protected, private

c. default, public

d. default, protected

The correct answer is: public, protected

/
Question 84 Consider 2 statements below:
Not answered (1) You can write a constructor of a sub class that invokes the constructor of the super class.
Marked out of 1.00 (2) You can write a new instance method in the sub class that has the same signature as the
one in the super class.
The statement (1) is ____, and (2) is ____

Select one:
a. true, true

b. false, true
c. true, false

d. false, false

The correct answer is: true, true

Question 85 public class Bike extends Bicycle { }


Not answered public class MountainBike extends Bike {}
Marked out of 1.00 and then:
1 Object obj1=new Bicycle();
2. MountainBike obj2=obj1;
Choose a right statement

Select one:
a. 1-false, 2-true

b. 1-true, 2-false

c. 1-false, 2-false
d. 1- true, 2 -true

The correct answer is: 1-true, 2-false

/
Question 86 What is the purpose of a constructor?
Not answered
Select one:
Marked out of 1.00
a. To pass values to methods for a class

b. To extend a class
c. To make objects initially have certain values when they are instantiated
d. To instantiate an object

The correct answer is: To make objects initially have certain values when they are
instantiated

Question 87 Introduce a new class by extending an existing class, this is an example of ___ .
Not answered
Select one:
Marked out of 1.00
a. Inheritance
b. Encapsulation

c. Interface
d. Polymorphism

The correct answer is: Inheritance

Question 88 Study the following code:


Not answered
public interface I1 {
Marked out of 1.00
void aMethod(int aValue){
System.out.println("Hi Mom");
}
}

Select one:
a. This code is invalid because the method aMethod does not access parameter.
b. This code is valid.

c. This code is invalid because the method aMethod must be prototype only.

The correct answer is: This code is invalid because the method aMethod must be prototype
only.

/
Question 89 Study the following code:
Not answered
public interface I1 {
Marked out of 1.00
void aMethod(int aValue){
System.out.println("Hi Mom");
}
}

Select one:
a. This code is valid.

b. This code is invalid because the method aMethod must be prototype only.
c. This code is invalid because the method aMethod does not access parameter.

The correct answer is: This code is invalid because the method aMethod must be prototype
only.

Question 90 Study declarations:


Not answered
(a)
Marked out of 1.00 public interface I1 {
}
(b)
public interface I2 {
void m();
}
The code (a) is ____, and (b) is ____

Select one:
a. invalid, invalid
b. valid, valid
c. valid, invalid

d. invalid, valid

The correct answer is: valid, valid

/
Question 91 Study declarations:
Not answered (a)
Marked out of 1.00 public interface I1 {
}
(b)
public interface I2 {
void m();
}
The code (a) is ____, and (b) is ____

Select one:
a. invalid, valid

b. invalid, invalid
c. valid, valid
d. valid, invalid

The correct answer is: valid, valid

Question 92 Study declarations:


Not answered (a)
Marked out of 1.00 public interface I1 {
}
(b)
public interface I2 {
void m();
}
The code (a) is ____, and (b) is ____

Select one:
a. valid, invalid
b. invalid, invalid

c. valid, valid
d. invalid, valid

The correct answer is: valid, valid

/
Question 93 What is a setter?
Not answered
Select one:
Marked out of 1.00
a. It is used to change a method.

b. It is used to initialize only a member variable.


c. It is used to find the value of a member variable
d. It is a method which is used to set or change a member variable.

The correct answer is: It is a method which is used to set or change a member variable.

Question 94 What happens if a variable or a method is private?


Not answered
Select one:
Marked out of 1.00
a. It cannot be accessed in other class except the class which they are declared
b. It can be accessed by any class inherited from the current class

c. It can be accessed from another object unrelated to the current one.

d. It cannot be accessed by an unrelated object from the outside.

The correct answer is: It cannot be accessed in other class except the class which they are
declared

/
Question 95 How do you create an instance of Box's Filler class?
Not answered class Box{
Marked out of 1.00 static class Filler{
int min, pref, max;
public Filler(int min, int pref, int max){
this.min = min;
this.pref = pref;
this.max = max;
}
}
}

Select one:
a. Box.Filler filler = new Box.Filler(1,2,3);

b. Box.Filler filler = new Filler(1,2,3);


c. new Box().new Filler(1,2,3);
d. Filler filler = new Box().new Filler(1,2,3);

The correct answer is: Box.Filler filler = new Box.Filler(1,2,3);

/
Question 96 How do you create an instance of Paragraph's Identation class?
Not answered class Paragraph{
Marked out of 1.00 class Indentation{
int left, right;
public Indentation(int left, int right){
this.left = left;
this.right = right;
}
}
}

Select one:
a. new Paragraph().Indentation(4,5);

b. Indentation ident =new Paragraph().Indentation(4,5);

c. new Paragraph().new Indentation(4,5);

d. Paragraph.new Indentation(4,5);

The correct answer is: new Paragraph().new Indentation(4,5);

/
Question 97 public class AA {
Not answered static {
Marked out of 1.00 System.out.println("This is a AA");
}
public void m() { System.out.println("This is a BB"); }
public static void main(String[] args) {
AA x=new AA();
x.m();
}
Choose a right statement for the code.

Select one:
a. This code will display:
This is a AA
This is a BB

b. Can not create an object without the constructor


c. syntax error

d. This code will display:


This is a BB

The correct answer is: This code will display:


This is a AA
This is a BB

Question 98 Which of the following statement is not a reason for using nested classes?
Not answered
Select one:
Marked out of 1.00
a. It increases encapsulation.

b. Nested classes can lead to more readable and maintainable code.

c. It is a way of logically grouping classes that are only used in one place.

The correct answer is: Nested classes can lead to more readable and maintainable code.

/
Question 99 What is class-level variable?
Not answered
Select one:
Marked out of 1.00
a. A non-static variable is defined within a class but outside any method

b. A variable is declared inside a method

c. A static variable that is defined within a class but outside any method

The correct answer is: A static variable that is defined within a class but outside any method

Question 100 We can apply java static keyword with variables, methods, ____ and nested class.
Not answered
Select one:
Marked out of 1.00
a. blocks

b. packages
c. constructors

d. outter classes

The correct answer is: blocks

Question 101 We can apply java static keyword with variables, methods, ____ and nested class.
Complete
Select one:
Mark 0.00 out of
1.00 a. constructors
b. outter classes

c. packages

d. blocks

The correct answer is: blocks

/
Question 102 We can apply java static keyword with variables, methods, ____ and nested class.
Complete
Select one:
Mark 0.00 out of
1.00 a. constructors

b. blocks
c. packages

d. outter classes

The correct answer is: blocks

Question 103 Consider 2 statements below:


Complete (1) Once a final variable has been assigned, it always contains the same value.
Mark 1.00 out of (2) final keyword can be applied only to variables, methods.
1.00
The statement (1) is ____, and (2) is ____

Select one:
a. true, true

b. false, true

c. true, false

d. false, false

The correct answer is: true, false

Question 104 Consider 2 statements below:


Complete (1) Once a final variable has been assigned, it always contains the same value.
Mark 1.00 out of (2) final keyword can be applied only to variables, methods.
1.00
The statement (1) is ____, and (2) is ____

Select one:
a. false, true

b. true, true

c. false, false
d. true, false

The correct answer is: true, false

/
Question 105 What kind of class do you use to logically group classes that are only used in one place?
Complete
Select one:
Mark 1.00 out of
1.00 a. local class

b. anonymous class
c. nested class

The correct answer is: nested class

Question 106 What kind of class do you use to logically group classes that are only used in one place?
Complete
Select one:
Mark 1.00 out of
1.00 a. local class

b. anonymous class
c. nested class

The correct answer is: nested class

Question 107 Regarding to the abstract class, which one of the following is NOT true ?
Complete
Select one:
Mark 0.00 out of
1.00 a. A class containing abstract methods is called an abstract class

b. An abstract class cannot have non-abstract methods

c. Abstract classes cannot be instantiated


d. Abstract methods are the ones without the body

The correct answer is: An abstract class cannot have non-abstract methods

/
Question 108 Regarding to the abstract class, which one of the following is NOT true ?
Complete
Select one:
Mark 0.00 out of
1.00 a. Abstract methods are the ones without the body

b. A class containing abstract methods is called an abstract class

c. An abstract class cannot have non-abstract methods


d. Abstract classes cannot be instantiated

The correct answer is: An abstract class cannot have non-abstract methods

Question 109 Select FALSE statement about static method in Java


Complete
Select one:
Mark 0.00 out of
1.00 a. Can access non static and static variables both

b. Can be called without any object creation of a class

c. Belongs to class not object of the class

The correct answer is: Can access non static and static variables both

Question 110 The ultimate ancestor of all Java classes is the ............ class.
Complete
Select one:
Mark 0.00 out of
1.00 a. Class

b. SuperClass

c. Starter

d. Ancestor

e. Object

The correct answer is: Object

/
Question 111 The Object's toString() method returns a string representation of the object which is very
Complete useful for debugging. This string includes the @ symbol, the class name of the object and
______.
Mark 0.00 out of
1.00
Select one:
a. a decimal number

b. the object' state

c. a binary number
d. a hexadecimal number

e. the object's behaviors

The correct answer is: a hexadecimal number

Question 112 The java.lang.String class represents for a ............string of characters.


Complete The java.lang.StringBuilder class represents for a ............string of characters.
Mark 1.00 out of
1.00 Select one:
a. mutable, modifiable

b. immutable, fixed

c. modifiable, immutable

d. immutable, dynamic modifiable

The correct answer is: immutable, dynamic modifiable

Question 113 What name is given to any class which is derived from another class?
Complete
Select one:
Mark 1.00 out of
1.00 a. Superclass

b. Underclass

c. Subclass
d. Overclass

The correct answer is: Subclass

/
Question 114 What is the output from the following code?
Complete class Product{
Mark 0.00 out of public void output(){
1.00 outputPrice();
outputDetail();
}
void outputPrice(){
System.out.print("Nothing.");
}
static void outputDetail(){
System.out.println("Nothing.");
}
}
class Car extends Product
{
public void outputPrice(){
System.out.print("Car’s price.");
}
public static void outputDetail(){
System.out.println("Car’s detail.");
}
}
public class Main {
public static void main(String[] args) {
Product car = new Car();
car.output();
}
}

Select one:
a. Nothing.Car’s detail.

b. Car’s price.Nothing.
c. Car’s price.Car’s detail.

d. Nothing.Nothing.

e. Nothing.Car’s price.

The correct answer is: Car’s price.Nothing.

/
Question 115 What is it called when an instance of a class is also an instance of its super class?
Complete
Select one:
Mark 1.00 out of
1.00 a. Polymorphism

b. Instantiation

c. Encapsulation

d. Inheritance

The correct answer is: Polymorphism

Question 116 What is it called when an instance of a class is also an instance of its super class?
Complete
Select one:
Mark 1.00 out of
1.00 a. Encapsulation
b. Inheritance

c. Polymorphism
d. Instantiation

The correct answer is: Polymorphism

Question 117 What is a subclass in Java?


Complete
Select one:
Mark 1.00 out of
1.00 a. subclass is a class that implements any interface

b. subclass is a class declared by using subclass keyword

c. subclass is a class that extends another class


d. subclass is a class declared inside a class

The correct answer is: subclass is a class that extends another class

/
Question 118 What is super keyword in Java used for?
Complete
Select one:
Mark 1.00 out of
1.00 a. refer to a object of parent class

b. refer to a object of current class


c. refer to a static method of the class

d. refer to a static variable of the class

The correct answer is: refer to a object of parent class

Question 119 What is super keyword in Java used for?


Complete
Select one:
Mark 1.00 out of
1.00 a. refer to a object of parent class
b. refer to a object of current class

c. refer to a static method of the class

d. refer to a static variable of the class

The correct answer is: refer to a object of parent class

Question 120 What is super keyword in Java used for?


Complete
Select one:
Mark 1.00 out of
1.00 a. refer to a static method of the class
b. refer to a object of parent class

c. refer to a object of current class


d. refer to a static variable of the class

The correct answer is: refer to a object of parent class

/
Question 121 If class B is sub class from class A then which is the correct syntax?
Complete
Select one:
Mark 1.00 out of
1.00 a. class B : A

b. class B implements A
c. class B extends class A

d. class B extends A

The correct answer is: class B extends A

Question 122 Order of execution of constructors in Java Inheritance is___.


Complete
Select one:
Mark 0.00 out of
1.00 a. base to derived class
b. random order

c. derived to base class

The correct answer is: base to derived class

Question 123 Order of execution of constructors in Java Inheritance is___.


Complete
Select one:
Mark 0.00 out of
1.00 a. random order

b. base to derived class


c. derived to base class

The correct answer is: base to derived class

/
Question 124 Which inheritance in Java programming is not supported?
Complete
Select one:
Mark 1.00 out of
1.00 a. Multiple inheritance using interfaces

b. Single inheritance
c. Multiple inheritance using classes

d. Multilevel inheritance

The correct answer is: Multiple inheritance using classes

Question 125 To prevent a class to be inherited/extended, the class should be___.


Complete
Select one:
Mark 1.00 out of
1.00 a. final class

b. final and abstract both

c. abstract class

d. nested class

The correct answer is: final class

Question 126 All of the numeric wrapper classes are sub classes of the abstract class________?
Complete
Select one:
Mark 1.00 out of
1.00 a. Integer, Float and Double
b. Integer

c. Integer and Float

d. Number

The correct answer is: Number

/
Question 127 Which the following cases are not auto boxing?
Complete
Select one or more:
Mark 0.00 out of
1.00 a. Integer j; j = 20;

b. Integer i = 10;

c. Integer k = new Integer(15);


d. int m = 5; Integer n = m;

The correct answer is: Integer k = new Integer(15);

Question 128 Consider the code:


Complete public class Main{
Mark 1.00 out of public static void main(String[] args) {
1.00 int result=97;
char result2;
String s1="HELLO";
String s2="hello";
if (s1!=s2)
result2=(char) result;
else
result2= 'T';
System.out.println( result2);
}
}
What is the output of above code ?

Select one:
a. true
b. a

c. T

d. false

The correct answer is: a

/
Question 129 Consider the code:
Complete public class Main{
Mark 1.00 out of public static void main(String[] args) {
1.00 int result=97;
char result2;
String s1="HELLO";
String s2="hello";
if (s1!=s2)
result2=(char) result;
else
result2= 'T';
System.out.println( result2);
}
}
What is the output of above code ?

Select one:
a. false

b. T
c. a

d. true

The correct answer is: a

Question 130 What method is used to tell whether or not matches the given regular expression?.
Complete
Select one:
Mark 1.00 out of
1.00 a. equals()

b. matches()

c. compareTo()

d. test()

The correct answer is: matches()

/
Question 131 If we use Math.random() method to random a number, which of the following numbers will
Complete never be appeared?

Mark 1.00 out of


Select one:
1.00
a. 0.2

b. 0.1

c. 1.0
d. 0.4

The correct answer is: 1.0

Question 132 What does the clone() method of the java.lang.Object class support?
Complete
Select one:
Mark 0.00 out of
1.00 a. Deep comparison

b. Deep copy

c. Shallow comparison

d. Shallow copy

The correct answer is: Shallow copy

Question 133 Suppose that we want to convert a string of digits to an integer, which of the following
Complete classes will be used?

Mark 0.00 out of


Select one:
1.00
a. String
b. Integer

c. NumString
d. Digit

The correct answer is: Integer

/
Question 134 Which of the following options is not a method of the Scanner class?
Complete
Select one:
Mark 1.00 out of
1.00 a. next()

b. nextInt()
c. nextValue()

d. nextDouble()

The correct answer is: nextValue()

Question 135 Which of following primitive data is wrapped by Integer data type?
Complete
Select one:
Mark 1.00 out of
1.00 a. double
b. float

c. char

d. int

The correct answer is: int

/
Question 136 Suppose that all needed packages are imported
Complete Consider below code:

Mark 1.00 out of public class Story {


1.00 String title;
public Story (String s1, String s2){
title=s1.concat(s2);
}
public String toString() {
return title.toUpperCase();
}
}
public class Demo{
public static void main(String[] args) {
String s=new String("Humpty Dumpty sat on a wall");
String [] arr=s.split("[, ,?,.]");
Story obj=new Story(srr[0],arr[1]);
System.out.println(obj.toString());
}
}
When Demo class is lunched, what is the output value ?

Select one:
a. humpty dumpty

b. HUMPTYDUMPTY
c. hUMPTYdUMPTY

d. Humpty Dumpty

The correct answer is: HUMPTYDUMPTY

/
Question 137 Suppose that all needed packages are imported
Complete Consider below code:

Mark 1.00 out of public class Story {


1.00 String title;
public Story (String s1, String s2){
title=s1.concat(s2);
}
public String toString() {
return title.toUpperCase();
}
}
public class Demo{
public static void main(String[] args) {
String s=new String("Humpty Dumpty sat on a wall");
String [] arr=s.split("[, ,?,.]");
Story obj=new Story(srr[0],arr[1]);
System.out.println(obj.toString());
}
}
When Demo class is lunched, what is the output value ?

Select one:
a. humpty dumpty

b. Humpty Dumpty
c. hUMPTYdUMPTY

d. HUMPTYDUMPTY

The correct answer is: HUMPTYDUMPTY

/
Question 138 Which of the following CAN NOT be stored in Character data type?
Complete
Select one:
Mark 1.00 out of
1.00 a. Special Character, e.g.$

b. String, e.g. Hello

c. Letter, e.g. A

The correct answer is: String, e.g. Hello

Question 139 Which of the following CAN NOT be stored in Character data type?
Complete
Select one:
Mark 1.00 out of
1.00 a. String, e.g. Hello
b. Letter, e.g. A

c. Special Character, e.g.$

The correct answer is: String, e.g. Hello

Question 140 The compiler converts primitive data type into object is called ____.
Complete
Select one:
Mark 1.00 out of
1.00 a. convert

b. implicit

c. boxing

d. cast

The correct answer is: boxing

/
Question 141 A file needs to be opened but it's name is not found in the target location then__
Complete
Select one:
Mark 1.00 out of
1.00 a. an exception will be thrown

b. exceptions are not thrown because of logic error

c. an exception might be thrown because of syntax error.


d. exceptions are not thrown.

The correct answer is: an exception will be thrown

Question 142 What is the output from the following code?


Complete class Person{
Mark 0.00 out of String name; int yob;
1.00
public Person(String name, int yob) {
this.name = name;
if (yob<0) throw new RuntimeException("Invalid Year of birth!");
this.yob = yob;
}
public static void main(String[] args) {
Person p = new Person("Tom", -18);
}
}

Select one:
a. Compile-time error

b. Nothing to output

c. Invalid Year of birth!


d. Run-time error

The correct answer is: Run-time error

/
Question 143 Choose a right statement about checked exceptions.
Complete 1. Checked exceptions is checked at compile time.
Mark 1.00 out of 2. Checked exceptions can not be handled by the program.
1.00

Select one:
a. true, true

b. true, false

c. false, true
d. false, false

The correct answer is: true, false

Question 144 Which package is imported by default into Java programs?


Complete
Select one:
Mark 1.00 out of
1.00 a. java.awt.font

b. java.lang

c. java.io
d. java.awt

The correct answer is: java.lang

Question 145 Select an operation which may cause an unchecked exception.


Complete
Select one:
Mark 1.00 out of
1.00 a. Accessing a remote resource.

b. Accessing an element of an array.

c. Accessing data in a file.


d. Accessing data in a database.

e. Controlling the state of a running thread.

The correct answer is: Accessing an element of an array.

/
Question 146

Complete

Mark 1.00 out of


1.00

Why does the row 5 of ClassB contain error?

Select one:
a. The sub-class is not more opened than it’s father

b. The ClassA and ClassB are the same package


c. The M3 method(in ClassB) has the same signature with father class.

d. The ClassB can not create the method M3 that is the same name in ClassA

The correct answer is: The sub-class is not more opened than it’s father

Question 147

Complete

Mark 1.00 out of


1.00

Why does the row 5 of ClassB contain error?

Select one:
a. The sub-class is not more opened than it’s father

b. The ClassB can not create the method M3 that is the same name in ClassA

c. The ClassA and ClassB are the same package


d. The M3 method(in ClassB) has the same signature with father class.

The correct answer is: The sub-class is not more opened than it’s father

/
Question 148 What is an immutable object?
Complete
Select one:
Mark 1.00 out of
1.00 a. The one has setter methods

b. The one has setter and getter methods


c. The one with no methods to modify its fields

The correct answer is: The one with no methods to modify its fields

Question 149
__(1)__ is used to postpone the handling of a checked exception and __(2)__ is used to
Complete
create an exception explicitly.
Mark 1.00 out of Choose a coincide keyword for (1) and (2)
1.00

Select one:
a. try ... catch , throw

b. exception , syntax error


c. assert, error

d. throws, throw

The correct answer is: throws, throw

/
Question 150
Suppose that all needed packages are imported
Complete Consider below code:
Mark 0.00 out of public class className {
1.00
public void deposit(double amount) throws Exception {
if(amount<0) throw new Exception(“error”);
}
public static void main(String[] args){
className obj=new className();
(*) obj.deposit(100);
}
}
Choose a the way to overcome a check exception at (*).

Select one:
a. using try...catch

b. using throws Exception in main method

c. nothing to do at there

The correct answer is: using try...catch

/
Question 151
Suppose that all needed packages are imported
Complete Consider below code:
Mark 0.00 out of public class className {
1.00
public void deposit(double amount) throws Exception {
if(amount<0) throw new Exception(“error”);
}
public static void main(String[] args){
className obj=new className();
(*) obj.deposit(100);
}
}
Choose a the way to overcome a check exception at (*).

Select one:
a. using try...catch

b. using throws Exception in main method

c. nothing to do at there

The correct answer is: using try...catch

/
Question 152
Suppose that all needed packages are imported
Complete Consider below code:
Mark 0.00 out of public class className {
1.00
public void deposit(double amount) throws Exception {
if(amount<0) throw new Exception(“error”);
}
public static void main(String[] args){
className obj=new className();
(*) obj.deposit(100);
}
}
Choose a the way to overcome a check exception at (*).

Select one:
a. nothing to do at there

b. using throws Exception in main method

c. using try...catch

The correct answer is: using try...catch

/
Question 153
public class ExcepTest {
Complete
public static void main(String args[]) {
Mark 1.00 out of
int a[] = new int[2];
1.00
try {
System.out.println("Access element three :" + a[3]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Exception thrown :" + e);
}finally {
a[0] = 6;
System.out.println("First element value: " + a[0]);
System.out.println("The finally statement is executed");
}
}
}
This method returns _______.

Select one:
a. Exception thrown :java.lang.ArrayIndexOutOfBoundsException: 3
First element value: 6
The finally statement is executed

b. Exception thrown :java.lang.ArrayIndexOutOfBoundsException: 3


c. syntax error

d. First element value: 6

The finally statement is executed

The correct answer is: Exception thrown :java.lang.ArrayIndexOutOfBoundsException: 3


First element value: 6
The finally statement is executed

/
Question 154
Suppose that all needed packages are imported
Complete Consider below code:
Mark 0.00 out of class CoffeeCup {
1.00 int temperature = 75;
//...
}
public class Person {
static final int tooCold = 65;
static final int tooHot = 85;
public void drinkCoffee(CoffeeCup cup) throws Exception{
int temperature = cup.temperature;
if (temperature <= tooCold)
throw new Exception("Too cold");
else
if (temperature >= tooHot)
throw new Exception("Too hot");
else
System.out.println(temperature + "is great");
}

//..
public static void main(String[] args){
Person a=new Person();
a.drinkCoffee(new CoffeeCup()); // (*)
}
}

The above code will display____

Select one:
a. 75 is great

b. A compilation error message is displayed at the row (*)

c. nothing is displayed

d. run time exception: 75 is great

The correct answer is: A compilation error message is displayed at the row (*)

/
Question 155
Suppose that all needed packages are imported
Complete Consider below code:
Mark 0.00 out of class CoffeeCup {
1.00 int temperature = 75;
//...
}
public class Person {
static final int tooCold = 65;
static final int tooHot = 85;
public void drinkCoffee(CoffeeCup cup) throws Exception{
int temperature = cup.temperature;
if (temperature <= tooCold)
throw new Exception("Too cold");
else
if (temperature >= tooHot)
throw new Exception("Too hot");
else
System.out.println(temperature + "is great");
}

//..
public static void main(String[] args){
Person a=new Person();
a.drinkCoffee(new CoffeeCup()); // (*)
}
}

The above code will display____

Select one:
a. A compilation error message is displayed at the row (*)

b. run time exception: 75 is great

c. 75 is great

d. nothing is displayed

The correct answer is: A compilation error message is displayed at the row (*)

/
Question 156 Choose a right statement.
Complete 1. It's necessary that each try block must be followed by a finally block.
Mark 0.00 out of 2. Using try...catch to throw an exception to other method.
1.00

Select one:
a. true, false

b. false, false
c. true, true

d. false, true

The correct answer is: false, false

Question 157 How can you iterate over the elements of a Set?
Complete
Select one:
Mark 0.00 out of
1.00 a. Using for-each statement: for (Object o : list) { System.out.println(o);}
b. Using iterators:while (iter.hasNext()) { System.out.println(iter.next());}

c. Using for statement: for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); }

The correct answer is: Using iterators:while (iter.hasNext()) { System.out.println(iter.next());}

Question 158 Choose a right statement about Collection framework.


Complete 1. Collection framework provides useful data structures and algorithms so you don't have to
Mark 1.00 out of write them yourself
1.00 2. Collection framework is a unified architecture for representing and manipulating
collections.

Select one:
a. false, false

b. false, true
c. true,true

d. true, false

The correct answer is: true,true

/
Question 159 A _____ can contain distinct elements only.
Complete
Select one:
Mark 1.00 out of
1.00 a. Vector

b. SortedSet

c. List
d. Queue

The correct answer is: SortedSet

Question 160 What package contains the Java collection framework?


Complete
Select one:
Mark 1.00 out of
1.00 a. java.collection

b. java.util

c. java.lang

d. java.framework

e. java.colectionframework

The correct answer is: java.util

Question 161 Which of the following option is correct?


Complete
Select one:
Mark 0.00 out of
1.00 a. Values stored in TreeSet are not allowed duplication

b. Values stored in ArrayList are automatically sorted

c. Values stored in Vector can be assessed through key-value pair.

The correct answer is: Values stored in TreeSet are not allowed duplication

/
Question 162 Which of the following collection cannot be used with Iterator class to traverse through
Complete elements?

Mark 1.00 out of


Select one:
1.00
a. TreeSet

b. HashMap
c. ArrayList

d. Array

The correct answer is: Array

Question 163 In Java Collection framework, which of the following pre-defined classes allow an element
Complete can be accessed through its index?

Mark 1.00 out of


Select one:
1.00
a. java.util.TreeSet

b. java.util.TreeMap

c. java.util.HashSet
d. java.util.ArrayList

The correct answer is: java.util.ArrayList

Question 164 Which of following is not a part of Java Collection Framework?


Complete
Select one:
Mark 1.00 out of
1.00 a. Map

b. List

c. File
d. Set

The correct answer is: File

/
Question 165 How to loop through a collection?
Complete
Select one:
Mark 0.00 out of
1.00 a. using foreach loop

b. using instruction "for"

c. using Enum type


d. using Iterator object

The correct answer is: using Iterator object

Question 166 How to loop through a collection?


Complete
Select one:
Mark 0.00 out of
1.00 a. using foreach loop

b. using Enum type

c. using instruction "for"


d. using Iterator object

The correct answer is: using Iterator object

/
Question 167 Suppose that all needed packages are imported
Complete Consider the below code:

Mark 0.00 out of public class className {


1.00 public static void main(String[] args){
Vector v=new Vector();
//... declare and intial for x
v.add( x ) ; (*)
}
}
What datatype is used to declare for the variable x?

Select one:
a. Generic type

b. Object
c. <T>

d. Number

The correct answer is: Object

Question 168 What is java.util.Collections?


Complete
Select one:
Mark 0.00 out of
1.00 a. Interface
b. Class

c. Object

d. extends

The correct answer is: Class

/
Question 169 Suppose that all needed packages are imported
Complete Consider below code:

Mark 1.00 out of public class Box {


1.00 int weight;
public Box(int weight) { this.weight=weight;}
// .....
}
public class MyClass{
public static void main(String[] args){
Treeset t=new TreeSet();
t.add(new Box(400));
t.add(new Box(200));
}
}
When the above code runs , it throws an exception. Why?

Select one:
a. Because Java finds duplicates in a TreeSet.

b. two objects are maintained in a sorted order

c. Because TreeSet object only add one class object


d. Box cannot be cast to comparable automatically

The correct answer is: Box cannot be cast to comparable automatically

Question 170 what method is used to return the number of elements in the specified collection equal to the
Complete specified object?

Mark 1.00 out of


Select one:
1.00
a. frequency

b. countElements

c. disjoint

d. binarySearch

The correct answer is: frequency

/
Question 171 what method is used to return the number of elements in the specified collection equal to the
Complete specified object?

Mark 1.00 out of


Select one:
1.00
a. disjoint

b. binarySearch

c. frequency

d. countElements

The correct answer is: frequency

Question 172 what method is used to return the number of elements in the specified collection equal to the
Complete specified object?

Mark 1.00 out of


Select one:
1.00
a. countElements

b. binarySearch

c. frequency

d. disjoint

The correct answer is: frequency

Question 173 What method is used to sort the collection?


Complete
Select one:
Mark 1.00 out of
1.00 a. sort

b. disjoint

c. binarySearch

d. descending

The correct answer is: sort

/
Question 174 What method is used to sort the collection?
Complete
Select one:
Mark 1.00 out of
1.00 a. binarySearch

b. descending

c. disjoint
d. sort

The correct answer is: sort

Question 175 Assume that all lib files are imported. What is the output from the following code?
Complete public class Sort {
Mark 1.00 out of public static void main(String[] args) {
1.00
String s = "java sort i walk the line";

String arr[] = s.split("[\\s]+");

List<String> list = Arrays.asList(arr);


Collections.sort(list);

System.out.println(list);
}

Select one:
a. [Ljava.lang.String;@15db9742]

b. Nothing to output

c. [walk the sort line java i]


d. [i, java, line, sort, the, walk]

The correct answer is: [i, java, line, sort, the, walk]

/
Question 176 Assume that all lib files are imported. What is the output from the following code?
Complete public class Sort {
Mark 1.00 out of public static void main(String[] args) {
1.00
List<String> list = new ArrayList<String>();

list.add("1");

list.add("123");

list.add("12");

Collections.sort(list, new Comparator<String>(){

@Override

public int compare(String o1, String o2) {

return o1.length() - o2.length();

});

System.out.println(list);

Select one:
a. [123, 12, 1]

b. Run-time error

c. [1, 12, 123]


d. [1, 123, 12]

The correct answer is: [1, 12, 123]

/
Question 177 Assume that all lib files are imported. What is the output from the following code?
Complete public class Sort {
Mark 1.00 out of public static void main(String[] args) {
1.00
List<String> list = new ArrayList<String>();

list.add("1");

list.add("123");

list.add("12");

Collections.sort(list, new Comparator<String>(){

@Override

public int compare(String o1, String o2) {

return o1.length() - o2.length();

});

System.out.println(list);

Select one:
a. Run-time error

b. [1, 12, 123]

c. [123, 12, 1]
d. [1, 123, 12]

The correct answer is: [1, 12, 123]

/
Question 178 Assume that all lib files are imported.
Complete public class test{
Mark 1.00 out of public static void main(String[] args) {
1.00 List<String> list=Array.asList(args);
Collections.sort(list);
System.out.println(list);
}
}
What is the output of above code when the program runs with arguments: "i" "go" "to"
"school"?

Select one:
a. [i, go, school, to]

b. [go, i, school, to]

c. [school, go, i, to]


d. [ to, school, i, go]

The correct answer is: [go, i, school, to]

Question 179 What class consists exclusively of static methods that operate on or return collections?
Complete
Select one:
Mark 1.00 out of
1.00 a. Arrays

b. Collection

c. Collections

d. Map

The correct answer is: Collections

/
Question 180 What class are methods such as reverse, shuffle offered in?
Complete
Select one:
Mark 1.00 out of
1.00 a. Collections

b. Object
c. Apache Commons Collections

d. Collection

The correct answer is: Collections

Question 181 What class are methods such as reverse, shuffle offered in?
Complete
Select one:
Mark 1.00 out of
1.00 a. Object
b. Apache Commons Collections

c. Collections

d. Collection

The correct answer is: Collections

Question 182 What kind of parameter type is used for a generic class to return and accept any types of
Complete object?

Mark 1.00 out of


Select one:
1.00
a. N

b. T

c. V

d. K

The correct answer is: T

/
Question 183 What kind of parameter type is used for a generic class to return and accept any types of
Complete object?

Mark 1.00 out of


Select one:
1.00
a. V

b. K

c. T
d. N

The correct answer is: T

Question 184 What kind of parameter type is used for a generic class to return and accept any types of
Not answered object?

Marked out of 1.00


Select one:
a. N

b. V

c. K

d. T

The correct answer is: T

/
Question 185 What is the output from the following code?
Complete public class Generics {
Mark 1.00 out of public static void main(String[] args) {
1.00
int n=10, m=20;

System.out.println(add(n, m));

}
public static <T> T add(T num1, T num2){

return num1 + num2;


}

Select one:
a. 0

b. Run-time error

c. Compile-time error
d. 30

The correct answer is: Compile-time error

/
Question 186 What is the output from the following code?
Complete public class Generics {
Mark 1.00 out of public static void main(String[] args) {
1.00
int n=10, m=20;

System.out.println(add(n, m));
}

public static <T> T add(T num1, T num2){

return num1 + num2;

Select one:
a. Run-time error

b. 30

c. Compile-time error
d. 0

The correct answer is: Compile-time error

Question 187 Assume that all lib files are imported. What is the output from the following code?
Complete public class Generics {
Mark 1.00 out of public static void main(String[] args) {
1.00
ArrayList list = new ArrayList<String>();

list.add("Hello Generics");

System.out.println(list);

Select one:
a. Compile-time error

b. Nothing to output

c. Run-time error

d. [Hello Generics]

The correct answer is: [Hello Generics]

/
Question 188 Assume that all lib files are imported. What is the output from the following code?
Complete public class Generics {
Mark 1.00 out of public static void main(String[] args) {
1.00
ArrayList list = new ArrayList<String>();

list.add("Hello Generics");

System.out.println(list);

Select one:
a. Compile-time error

b. Run-time error
c. [Hello Generics]

d. Nothing to output

The correct answer is: [Hello Generics]

Question 189 In which situation are generic collections used?


Complete
Select one:
Mark 0.00 out of
1.00 a. The collection contains elements which belong to some classes.

b. The collection contains homogenous elements.

c. The collection contains elements which belong to exactly two classes.

The correct answer is: The collection contains homogenous elements.

Question 190 Which of these class is used to read characters in a file?


Complete
Select one:
Mark 0.00 out of
1.00 a. FileInputStream

b. FileWriter
c. FileReader

d. ObjectInputStream

The correct answer is: FileReader

/
Question 191 Which of these class is used to read characters in a file?
Complete
Select one:
Mark 0.00 out of
1.00 a. FileWriter

b. FileInputStream
c. ObjectInputStream

d. FileReader

The correct answer is: FileReader

Question 192 Use _____________ to serialize an object.


Complete
Select one:
Mark 1.00 out of
1.00 a. java.io.Serializable

b. java.io.ObjectInputStream

c. java.io.Deserializable

d. java.io.ObjectOutputStream

The correct answer is: java.io.Serializable

Question 193 The process of writing an object is called ____.


Complete
Select one:
Mark 1.00 out of
1.00 a. ObjectInputStream
b. Serialization

c. ObjectOutputStream

d. De-serialization

The correct answer is: Serialization

/
Question 194 The process of writing an object is called ____.
Complete
Select one:
Mark 1.00 out of
1.00 a. ObjectOutputStream

b. ObjectInputStream

c. De-serialization

d. Serialization

The correct answer is: Serialization

Question 195 What classes are used to return/write a unicode string?.


Complete
Select one:
Mark 1.00 out of
1.00 a. FileReader, FileWriter

b. DataInputStream, DataOutputStream

c. ObjectInputStream, ObjectOutputStream

d. Reader, Writer

The correct answer is: DataInputStream, DataOutputStream

Question 196 Which package needs to be imported so that you can accept user input?
Complete
Select one:
Mark 1.00 out of
1.00 a. java.io

b. java.awt.event

c. java.util

d. java.awt

The correct answer is: java.io

/
Question 197 In _____ binary streams, a read/write data unit is _______.
Complete
Select one:
Mark 0.00 out of
1.00 a. high-level, byte

b. low-level, byte

c. low-level, general-format data


d. low-level, primitive data

The correct answer is: low-level, byte

Question 198 In _____ binary streams, a read/write data unit is _______.


Complete
Select one:
Mark 0.00 out of
1.00 a. low-level, primitive data

b. low-level, byte

c. low-level, general-format data

d. high-level, byte

The correct answer is: low-level, byte

Question 199 Select a correct statement.


Complete
Select one:
Mark 0.00 out of
1.00 a. DataInputStream, DataOutputStream are binary streams.

b. ObjectInputStream, ObjectOutputStream are text streams.

c. DataInputStream, DataOutputStream are text formatted streams.


d. PrintWriter, BufferedReader are low-level streams.

The correct answer is: DataInputStream, DataOutputStream are binary streams.

/
Question 200 When reading objects from an object stream, we usually use _____.
Complete
Select one:
Mark 0.00 out of
1.00 a. an implicit class conversion

b. an explicit class casting

c. no type changes

The correct answer is: an explicit class casting

Dream of Innovation.

Quick Links
About Us

Terms of use

FAQ

Support

Follow Us

Contact
Innovation Building, QTSC, D.12, HCMc
 Phone: (848) 543 711 97
 E-mail: [email protected]

Copyright © 2015 - Developed by Nephzat.com.Powered by Moodle

You might also like