[go: up one dir, main page]

0% found this document useful (0 votes)
32 views9 pages

Progress Test 2 - Key Spring20

Uploaded by

dihoc77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

Progress Test 2 - Key Spring20

Uploaded by

dihoc77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROGRESS TEST 2

1. Assume that all classes are the same package.

public class Shape {

int side = 100;

private void showSide(){

System.out.println(side);

}
}

public class Square extends Shape{

void showSide() {

System.out.println(side/10);

[1] public static void main(String[] args){

[2] Shape sh=new Square();

[3] sh.showSide();

}
}
a. 100
b. 10
c. can not access the private method at row [3]
d. syntax error at row [2]

2. Which of the following are not acceptable


a. Queue<Integer> queue = new LinkedList<>();
b. Boolean flag = true;
c. Character c = 'a';
d. Queue<Integer> queue = new Queue<>();
3. What is the output value of this code

import java.util.*;

public class Example {

public static void main(String[] args) {

ArrayList<String> list = new ArrayList<String>();

list.add("jQuery");

list.add("is");

list.add("a");

list.add("JavaScript");

list.add("Library");

Collections.sort(list);

System.out.println(list);

a. [jQuery, is, a, JavaScript, Library]


b. [JavaScript, Library, a, is, jQuery]
c. throws an exception
d. compile-time error

4. What is the output of the following program

a. Compile-time error
b. 12
c. 21
d. Unpredictable output

5. What is the output from the following code?


class Example {
public float a;
}
public class Main {
public static void main(String[] args) {
Example ex;
ex.a = 1.5f;
System.out.print(ex.a);
}
}
a. 1.5f
b. Error
c. 1.5
d. None of the others

6. Which option of the following statements about input byte streams is false
a. A low-level input stream returns bytes to its caller
b. A high-level filter input stream returns general-format data to its caller
c. A high-level filter input stream reads bytes from a low-level input stream, or
from another filter input stream
d. A low-level input stream reads bytes from a high-level input stream

7. Suppose that all nseeded packages are imported


What is the output of this program?
class BaseClass {
public void foo() {
System.out.print("Base class");
}
}
class SubClass extends BaseClass {
public void foo() {
System.out.print("Sub class");
}
public static void main(String[] args) {
SubClass s = new SubClass();
s.foo();
}
}
a. Base class
b. Sub classBase class
c. Sub class
d. Runtime error

8. What is wrong with below source code?


public interface IShape1 {
void f1();
}

public interface IShape2 {


void f2();
}

class Circle implements IShape1, IShape2 {


public void f1() {
}
}

a. Runtime error
b. The source code is no problem
c. Compile-time error: class Circle can’t imlement both interface IShape1, IShape2
d. Compile-time error: class Circle does not override abstract method f2

9. What is output of below Java program?


interface X {
void f();
}
interface Y extends X {
void g();
}
class C implements Y {
public void f() {
System.out.print("Hello");
}
public void g() {
System.out.print("World");
}
public static void main(String[] args) {
C o = new C();
o.f();
o.g();
}
}
a. HelloWorld
b. Hello
c. World
d. Compile error

10. What is output of below Java program?

public class Study_1A {


void m() {
System.out.print("A");
}
}
public class Study_1B extends Study_1A {
void m() {
System.out.print("B");
}
}
public class Study_1 {
public static void main(String[] args){
Study_1A obj = new Study_1B();
obj.m();
obj= new Study_1A();
obj.m();
}
}
a. AA
b. BB
c. BA
d. Compile-time error

11. All of the numeric wrapper classes are subclasses of the class ________?

a. Integer
b. Number
c. Wrapper
d. String
12. A wrapper class encapsulates a single ......... value.

Wraper classes support methods for ..........

a. immutable, type conversion


b. mutable, type conversion
c. modifiable, input data
d. immutable, output data

13. What is the output of the following code?


public class Generics {

public static void main(String[] args) {


int n=9, m=7;
System.out.println(Generics.add(n, m));
//System.out.println(add(n, m));

}
public static <T extends Number> double add(T num1, T num2){
return num1.doubleValue() + num2.doubleValue();
}

}
a. Compile-time error
b. Runtime error
c. 16
d. All of the others

14. Suppose that all needed packages are imported.

What is the output value ?

public class Story {

String title;
public Story (String s1, String s2){
title=s1.concat(s2);
}
public String toString() {
return title.toUpperCase();
}
public static void main(String[] args) {
String s=new String("Humpty Dumpty sat on a wall");
String [] arr=s.split("[, ,?,.]");
Story obj=new Story(arr[0],arr[1]);
System.out.println(obj.toString());
}
}
a. hUMPTYdUMPTY
b. HUMPTYDUMPTY
c. humpty dumpty
d. Humpty Dumpty

15. What is the output value ?

class AA {

int i;

int j;

AA() {

i = 1;

j = 2;

public static void main(String args[]) {

AA obj1 = new AA();

AA obj2 = new AA();

System.out.print(obj1.equals(obj2));

System.out.print(obj1 == obj2);

}
}
a. falsetrue
b. truefalse
c. falsefalse
d. truetrue

16. Study declarations:


(a)
public interface I1 {
}
(b)
public interface I2 {
void m();
}
The code (a) is ____, and (b) is ____
a. valid, valid
b. valid, invalid
c. invalid, valid
d. invalid, invalid

17. The fields in an interface are implicitly specified as ________


a. static and public
b. final and public
c. final and private
d. static and final

18. What is the output from the following code?


package a;
public class Vehicle {
protected double speed;
public void show(){
System.out.println(speed);
}
}
package b;
import a.Vehicle;
public class Bicycle extends Vehicle{
public Bicycle() {
this.speed = 15;
}
public static void main(String[] args){
Vehicle v = new Bicycle();
v.show();
}
}
a. 0
b. can not access the field speed from class Vehicle
c. 15.0
d. can not access the method show in class Bicycles

19. __(1)__ is used to postpone the handling of a checked exception and __(2)__ is
used to invoke an exception explicitly.
postpone the handling: dừng xử lý = cho qua ngoại lệ throws = khai báo ngoại lệ
(declare)
to invoke an exception explicitly: = throw đối tượng ngoại lệ
so sánh từ khóa throws declare exception, throw exception

Choose a coincide keyword for (1) and (2)

a. exception , syntax error


b. assert, error
c. try ... catch , throw
d. throws, throw

20. Which of these methods sets every element of a List to a specified object?
a. set()
b. fill()
c. complete()
d. add()

You might also like