Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
mcq.docx
Скачиваний:
12
Добавлен:
25.02.2016
Размер:
29.56 Кб
Скачать
    • III only

    • II and III only

    • I only

    • II only

  • Consider the following class definitions.

public class Publication {

private String author;

public Publication() {

this.author = "anonymous";

}

public Publication(String author) {

this.author = author;

}

}

public class Book extends Publication {

private int edition;

//Constructor(s) to be added here

}

Which of the following constructors can be added to the definition of class Book without causing compilation to fail?

  • public Book(String author) {

  • this.author = author;

  • }

  • public Book(String author, int edition) {

  • this.edition = edition;

  • super(author);

  • }

  • public Book(int edition) {

  • super();

  • this.edition = edition;

  • }

    • I and III only

    • I and II only

    • II only

    • III only

  • Which of the following statements about Java is (are) true?

  • One class can define two methods with the same signature.

  • If class B extends class A and overrides method m, then the argument names in the definition of method m in class B must be identical to those in class A.

    • I only

    • II only

    • I and II

    • None

  • Which of the following statements about Java constructors is (are) true?

  • The signature of a constructor can include a return type.

  • The name of a constructor for a class can differ from the name of the class.

  • A constructor can be invoked using the dot notation.

    • I only

    • II and III only

    • I and III only

    • None

  • Which of the following statements about static attributes in Java is (are) true?

  • Static attributes can be accessed by non-static methods in the same class.

  • A static attribute can be accessed even if no instance of the class in which the attribute is defined exists.

  • Static attributes can only be accessed by static methods.

    • I only

    • II only

    • I, II, and III

    • I and II only

  • Consider the following Java class definitions.

public class Publication {

private String author;

public Publication() {

this.author = "anonymous";

}

public String getAuthor() {

return author;

}

}

public class Book extends Publication {

private int edition;

//No default constructor

public Book(int edition) {

this.edition = edition;

}

}

Based on these class definitions, which of the following program segments will compile?

  • Book book = new Book(2);

  • System.out.println(book.author);

  • Book book = new Book(2);

  • System.out.println(book.getAuthor());

  • Book book = new Book();

    • III only

    • I only

    • I and II only

    • II only

  • Which of the following statements about Java constructors is (are) true for any given class?

  • Constructors can be overloaded.

  • If a constructor is not defined, then one will be automatically created.

  • One constructor can invoke another constructor using the keyword this.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]