Test 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

d

An abstract class ____. Select one: a. is a superclass with many subclasses b. does not have any subclasses c. is the base class of all other classes d. cannot be instantiated

a

An abstract class can contain ____. Select one: a. abstract and non-abstract methods b. only abstract methods c. nothing d. only non-abstract methods

b

How the main method header is written in Java? Select one: a. public static main(String[] args) b. public static void main(String[] args) Correct c. public static void main(string[] args) d. public static void Main(String[] args) e. public void main(String[] args).

c

What is the extension name of a Java source code file? Select one: a. .obj b. .class c. .java d. .exe e. .javac.

d

A process that involves recognizing and focusing on the important characteristics of a situation or object is known as: Select one: a. Polymorphism b. Object persistence. c. Inheritance d. Abstraction e. Encapsulation

b

An abstract class can only contain abstract methods. Select one: a. True b. False

d

Consider, public class MyClass { public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write? Select one: a. MyClass mc = new MyClass; b. MyClass mc = MyClass(); c. MyClass mc = MyClass; d. MyClass mc = new MyClass(); e. The constructor of MyClass should be defined as, public void MyClass(){/*code*/}.

a

How many interfaces can a class implement? Select one: a. There is no limit to the number of interfaces that can be implemented by a single class. b. 2 c. 0 d. 1

b

If a class implements an interface, it must ____. Select one: a. override all variables from the interface b. provide definitions for each of the methods of the interface c. override all constants from the interface d. rename all the methods in the interface Feedback

a

Redefining a method of a superclass is also known as overloading a method. Select one: a. False b. True

d

The extends keyword creates a new Select one: a. Instance b. Superclass c. Baseclass d. Subclass e. Object.

b

The superclass inherits all its properties from the subclass. Select one: a. True b. False

a

What is byte code in the context of Java? Select one: a. The type of code generated by a Java compiler. b. It is another name for comments written within a program. c. It is another name for a Java source file. d. The type of code generated by a Java Virtual Machine. e. It is the code written within the instance methods of a class.

c

What is the correct syntax for defining a new class Parakeet based on the superclass Bird? Select one: a. class Parakeet isa Bird{ } b. class Bird hasa Parakeet{ } c. class Parakeet extends Bird{ } d. class Bird defines Parakeet{ }

a, e

Among these expressions, which is(are) of type String (select 2)? Select one or more: a. "ab" + "cd" b. '\t' c. '0' d. '\n' e. "0"

a, b

An overloaded method consists of (select 2), Select one or more: a. The same method name with different types of parameters b. The same method name with different number of parameters c. The same method name and same number and type of parameters with different return type d. Other answers e. There is no concept of overloaded method

a, b

Consider the following class definition: public class MyClass { private int value; public void setValue(int i){ /* code */ } // Other methods... } The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue (select 2)? Select one or more: a. value = i; b. this.value = i; c. value == i; d. i = value e. i == value

d

Consider the following class definitions. public class BClass { private int x; private double y; public void print() { } } public class DClass extends BClass { private int a; private int b; public void print() { } } Suppose that you have the following statement. DClass dObject = new DClass(); How many instance variables DObject has? Select one: a. 0 b. 4 c. None of these d. 2

c

Consider the following class definitions. public class BClass { private int x; public void set(int a) { x = a; } public void print(){ } } public class DClass extends BClass { private int y; public void set(int a, int b) { //Postcondition: x = a; y = b; } public void print(){ } } Which of the following is the correct definition of the method set of the class Dclass? (i) public void set(int a, int b) { super.set(a); y = b; } (ii) public void set(int a, int b) { x = a; y = b; } Select one: a. Both (i) and (ii) b. Only (ii) c. Only (i) d. None of these

b

Consider the following program written in Java. class Selection{ public static void main(String args[]){ int x=7; if(x==2); //? Note the semicolon System.out.println("Number seven"); System.out.println("Not seven"); } } What would the output of the program be? Select one: a. 7 b. Number seven Not seven c. Error d. Not seven e. Number seven

b

Given a class named Student, which of the following is a valid constructor declaration for the class? Select one: a. private final Student { } b. Student (Student s) { } c. Void Student { } d. Student Student { } e. static Void Student { }

d

Given the code below: class A { public void print() { System.out.println("hi"); } } class B extends A { public void print() { System.out.println("bye"); } } What does each of the following code samples do: A a = new B(); a.print(); Select one: a. The code throws a runtime exception. b. Prints nothing c. Prints "hi" d. Prints "bye" e. The code does not compile, the compiler returns a type error

b

If class Dog has a subclass Retriever, which of the following is true? Select one: a. The relationship between these classes implies that Retriever "has-a" Dog. b. Because of single inheritance, Retriever can extend no other class except Dog. c. The relationship between these classes implies that Dog "is-a" Retriever. d. Because of single inheritance, Dog can have no other subclasses.

b

Suppose static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is the printout of the call Print('a', 4)? Select one: a. aaaaa b. invalid call. c. aaaa d. aaa e. aa

c

Suppose that the class Mystery is derived from the class Secret. Consider the following statements: Secret mySecret = new Secret(); Secret secRef; Mystery myMystery = new Mystery(); Mystery mysRef; secRef = myMystery; Which of the following statements is legal in Java? (i) mysRef = (Mystery) mySecret; (ii) mysRef = (Mystery) secRef; Select one: a. None of these b. Only (i) c. Both (i) and (ii) d. Only (ii)

a

Suppose that the class Mystery is derived from the class Secret. The following statements are legal in Java. Secret secRef; Mystery mysRef = new Mystery(); secRef = mysRef; Select one: a. true b. false

a

What is the correct syntax for defining a new class Parakeet based on the superclass Bird? Select one: a. class Parakeet extends Bird{ } b. class Bird defines Parakeet{ } c. class Bird hasa Parakeet{ } d. class Parakeet isa Bird{ }

b

What type of inheritance does Java support? Select one: a. multiple inheritance b. single inheritance c. Java does not support inheritance d. double inheritance

b

Which of the following is not a valid String Constant? Select one: a. "Hello Guys". b. 'x' c. "2002" d. "Hello" e. "X"

d

Which of the following statements about the reference super is true? Select one: a. It can only be used once in a program. b. It must be used every time a method from the superclass is called. c. It must be the last statement of the constructor. d. It must be the first statement of the constructor.

e

Which of these combinations of switch expression types and case label value types are legal within a switch statement? Select one: a. switch expression of type boolean and case label value of type boolean. b. switch expression of type char and case label value of type long c. switch expression of type byte and case label value of type float d. switch expression of type float and case label value of type int e. switch expression of type int and case label value of type char

a

Which operator is used to determine if an object is of a particular class type? Select one: a. The instanceof operator b. The operator new c. The + operator d. The dot (.) operator

a

Which statement is true regarding an object? Select one: a. An object is a reference to an attribute b. An object is what classes instantiated are from c. An object is a variable d. An object is not an instance of a class. e. An object is an instance of a class


Kaugnay na mga set ng pag-aaral

AP GOV Three Branches Chap 6,7,8,9

View Set

Project Development & Documentation 2

View Set

Deliver the Right Message With Text Ads: module 4

View Set

CCMA Anatomy and Physiology Questions

View Set

Chapter 2 Government: Majoritarian or Pluralist Democracy. (Study Guide).

View Set

Quartier français 6 Un malheur n'arrive jamais seul (Vocabulaire actif)

View Set