Overloading 練習(

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

class Parent {

publicjava.util.Set<String> set;

}

package dir2;

class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

class Parent {

protectedjava.util.Set<String> set;

}

package dir2;

class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

public class Parent {

publicjava.util.Set<String> set;

}

package dir2;

public class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

public class Parent {

protectedjava.util.Set<String> set;

}

package dir2;

public class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

class Parent {

java.util.Set<String> set;

}

package dir2;

class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in separate files. Will this code compile successfully? (1 correct answer)

package dir1;

class Parent {

privatejava.util.Set<String> set;

}

package dir2;

class Child extends dir1.Parent {

void test() {

set.add("Hello");

}

}

Yes.

No.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

System.out.println(new Parent().message);

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

System.out.println(new Child().message);

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

System.out.println(yo.message);

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

new Parent().say();

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

new Child().say();

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

yo.say();

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

void say() {

System.out.println(message);

}

}

public class Test {

public static void main(String[] args) {

new Parent().say();

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

void say() {

System.out.println(message);

}

}

public class Test {

public static void main(String[] args) {

new Child().say();

}

}

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

String message = "parent";

void say() {

System.out.println(message);

}

}

class Child extends Parent {

String message = "child";

void say() {

System.out.println(message);

}

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

yo.say();

}

}

parent

child

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

static void say() {

}

}

class Child extends Parent {

void say() {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() {

}

}

class Child extends Parent {

static void say() {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws Exception {

}

}

class Child extends Parent {

void say() {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws Exception {

}

}

class Child extends Parent {

void say() throws Exception {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

import java.io.*;

class Parent {

void say() throws Exception {

}

}

class Child extends Parent {

void say() throws IOException, FileNotFoundException {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws Exception {

}

}

class Child extends Parent {

void say() throws RuntimeException {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws PovertyException {

}

}

class Child extends Parent {

void say() throws NoFoodException {

}

}

classPovertyException extends Exception {

}

classNoFoodException extends PovertyException {

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws PovertyException {

}

}

class Child extends Parent {

void say() throws NoFoodException, IOException {

}

}

classPovertyException extends Exception {

}

classNoFoodException extends PovertyException {

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws NoFoodException {

}

}

class Child extends Parent {

void say() throws PovertyException {

}

}

classPovertyException extends Exception {

}

classNoFoodException extends PovertyException {

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() throws Exception {

}

}

class Child extends Parent {

void say() throws ArrayIndexOutOfBoundsException,

ClassCastException, NullPointerException {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() {

}

}

class Child extends Parent {

void say() throws ArrayIndexOutOfBoundsException,

ClassCastException, NullPointerException {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

<T> void say() {

}

}

class Child extends Parent {

void say() {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say() {

}

}

class Child extends Parent {

<T> void say() {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

void say(Number number) {

}

}

class Child extends Parent {

<T extends Number> void say(T number) {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

Number get() {

return 1;

}

}

class Child extends Parent {

Integer get() {

return 2;

}

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

System.out.println(yo.get());

}

}

1

2

Compilation fails.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

Integer get() {

return 1;

}

}

class Child extends Parent {

Number get() {

return 2;

}

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

System.out.println(yo.get());

}

}

1

2

Compilation fails.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

Float get() {

return 1.0f;

}

}

class Child extends Parent {

Integer get() {

return 2;

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

Double get() {

return 1.0;

}

}

class Child extends Parent {

Integer get() {

return 2;

}

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

Integer get() {

return 1;

}

}

class Child extends Parent {

Double get() {

return 2.0;

}

}

Yes.

No.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

void show(Parent parent) {

System.out.println("parent");

}

}

class Child extends Parent {

void show(Child child) {

System.out.println("child");

}

}

public class Test {

public static void main(String[] args) {

Parent parent = new Parent();

Child child = new Child();

child.show(child);

}

}

parent

child

Compilation fails.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

void show(Parent parent) {

System.out.println("parent");

}

}

class Child extends Parent {

void show(Child child) {

System.out.println("child");

}

}

public class Test {

public static void main(String[] args) {

Parent parent = new Parent();

Child child = new Child();

child.show(parent);

}

}

parent

child

Compilation fails.

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Parent {

void show(Parent parent) {

System.out.println("parent");

}

}

class Child extends Parent {

void show(Child child) {

System.out.println("child");

}

}

public class Test {

public static void main(String[] args) {

Parent parent = new Child();

Child child = new Child();

child.show(parent);

}

}

parent

child

Compilation fails.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

static Integer number;

}

class Child extends Parent {

Integer number;

}

Yes.

No.

------

  1. These classes are defined in the same file. Will this code compile successfully? (1 correct answer)

class Parent {

Integer number;

}

class Child extends Parent {

static Integer number;

}

Yes.

No.

------

  1. These classes are defined in the same file and compilation succeeds. What is the output? (1 correct answer)

class Parent {

Integer a = 1;

static Integer b = 2;

}

class Child extends Parent {

static Integer a = 41;

Integer b = 42;

}

public class Test {

public static void main(String[] args) {

Parent parent = new Parent();

Child child = new Child();

Parent yo = new Child();

System.out.format("%d %d %d %d %d %d ",

parent.a,

parent.b,

child.a,

child.b,

yo.a,

yo.b);

}

}

1 2 41 42 1 2

1 2 41 42 41 42

1 2 41 42 1 42

1 2 41 42 41 2

------

  1. These classes are defined in the same file and compilation succeeds. What is the output? (1 correct answer)

class Parent {

final Integer a = 1;

final static Integer b = 2;

}

class Child extends Parent {

final static Integer a = 41;

final Integer b = 42;

}

public class Test {

public static void main(String[] args) {

Parent parent = new Parent();

Child child = new Child();

Parent yo = new Child();

System.out.format("%d %d %d %d %d %d ",

parent.a,

parent.b,

child.a,

child.b,

yo.a,

yo.b);

}

}

1 2 41 42 1 2

1 2 41 42 41 42

1 2 41 42 1 42

1 2 41 42 41 2

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Grandparent {

String name = "granparent";

void act() {

System.out.println(name);

}

}

class Parent extends Grandparent {

String name = "parent";

}

class Child extends Parent {

String name = "child";

void act() {

System.out.println(name);

}

}

public class Test {

public static void main(String[] args) {

Grandparent yo = new Child();

yo.act();

}

}

grandparent

parent

child

Compilation fails

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Grandparent {

String name = "granparent";

void act() {

System.out.println(name);

}

}

class Parent extends Grandparent {

String name = "parent";

}

class Child extends Parent {

String name = "child";

void act() {

System.out.println(name);

}

}

public class Test {

public static void main(String[] args) {

Parent yo = new Child();

yo.act();

}

}

grandparent

parent

child

Compilation fails

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Grandparent {

String name = "granparent";

void act() {

System.out.println(name);

}

}

class Parent extends Grandparent {

String name = "parent";

}

class Child extends Parent {

String name = "child";

void act() {

System.out.println(name);

}

}

public class Test {

public static void main(String[] args) {

Parent yo = new Parent();

yo.act();

}

}

grandparent

parent

child

------

  1. These classes are defined in the same file. What is the output? (1 correct answer)

class Grandparent {

String name = "granparent";

void act() {

System.out.println(name);

}

}

class Parent extends Grandparent {

String name = "parent";

}

class Child extends Parent {

String name = "child";

void act() {

System.out.println(name);

}

}

public class Test {

public static void main(String[] args) {

Grandparent yo = new Parent();

yo.act();

}

}

grandparent

parent

child

Compilation fails

------

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method() {

}

static void method() {

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method() {

}

static void method() throws Exception {

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method() {

}

static Object method() {

return null;

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

importjava.util.List;

class Overload {

public void method(List<String> names) {

}

private static Object method(String... names) {

return null;

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method(String[] names) {

}

final Object method(String... names) {

return null;

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method(String[] names) {

}

final Object method(String name, String... names) {

return null;

}

}

Yes.

No.

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method(String name, String[] names) {

}

final Object method(String... names) {

return null;

}

}

Yes.

No.

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method(String name, String[] names) {

}

final Object method(String name, String... names) {

return null;

}

}

Yes.

No.

  1. Will this code compile successfully? (1 correct answer)

class Overload {

public void method(String name, String[] names) {

}

final Object method(String... names, String name) {

return null;

}

}

Yes.

No.

  1. Will this code compile successfully? (1 correct answer)

importjava.util.*;

class Overload {

void method(NavigableSet<Integer> set) {

}

void method(NavigableSet<String> set) {

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

importjava.util.*;

class Overload {

void method(SortedSet<String> set) {

}

void method(NavigableSet<String> set) {

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

importjava.util.*;

class Overload {

void method(Set<String>... set) {

}

void method(Set<String> set) {

}

void method(NavigableSet<String> set) {

}

}

Yes.

No.

------

  1. Will this code compile successfully? (1 correct answer)

importjava.util.NavigableSet;

interfaceInterface {

void method(NavigableSet<String> set) throws Exception;

}

public class Overload implements Interface {

void method() {

}

void method(NavigableSet<String> set) throws Exception {

}

}

Yes.

No.

------

  1. These classes are defined in the same file. What is the output of this code? (1 correct answer)

class Parent {

int value;

void validate() {

value = value + 10;

}

}

class Child extends Parent {

void validate() {

super.validate();

value = value - 2;

}

}

public class Run {

public static void main(String[] args) {

Child child = new Child();

child.validate();

System.out.println(child.value);

}

}

It prints “8″.

It prints “-2″.

None of the above.

------

  1. These classes are defined in the same file. What is the output of this code? (1 correct answer)

class Parent {

int value;

void validate() {

value = value + 10;

}

}

class Child extends Parent {

int value;

void validate() {

super.validate();

value = value - 2;

}

}

public class Run {

public static void main(String[] args) {

Child child = new Child();

child.validate();

System.out.println(child.value);

}

}

It prints “8″.

It prints “-2″.

None of the above.