SSD3 Multiple-Choice Quiz 3

来源:互联网 发布:ubuntu 唤醒后 编辑:程序博客网 时间:2024/06/03 18:58


1. The return type for a method thatreturns nothing to its caller is    

(a) false

(b) void

(c) null

(d) not specified in the method definition

Correct answer is   (b)

 

2.    Whichof the following statements about class variables in Java is not true?

(a) Non-static methods in a class canaccess the class variable defined in the same class.

(b) Class variables do not need thereference to the object of the instantiated class to access them.

(c) Class variables require the modifierstatic in the declarations.

(d) All objects have their own copy of theclass variable defined in the instantiated class.

Correct answer is   (d)

         3.  

         Whatis used to indicate that a method does not return a value? (a) the name of theclass to which it belongs

(b) the keyword static

(c) the keyword void

(d) the omission of the return type

 

         Correctanswer is   (c)

         4.

Consider the following Java programsegment.

   import java.io.*;

                      

   public class Test {

                      

       public Test( ) {

                      

           System.out.println("default");

       }

                      

       public Test( int i ) {

                      

           System.out.println("non-default");

       }

                      

       public static void main(String[] args) {

                      

           Test t = new Test(2);

       }

    }

 

Which of the following will be outputduring execution of the program segment?

(a) The line of text"non-default"

(b) The line of text "default"

(c) The line of text "default"followed by the line of text "non-default"

(d) The line of text"non-default" followed by the line of text "default"

 

         Correctanswer is   (a)

         5.

Which of the following statements aboutconstructors in Java is true?

(a) A class can define more than oneconstructor.

(b) A constructor must be defined asstatic.

(c) A constructor must be defined aspublic.

(d) A class must define at least oneconstructor.

 

         Correctanswer is   (a)

         6.  

         Whichis the Java keyword used to denote a class method?

(a) class

(b) final

(c) private

(d) static

 

         Correctanswer is   (d)

         7.  

If the method int sum(int a, int b) isdefined in a Java class C, which of the following methods cannot coexist as adifferent method in class C?

(a) float sum(int x, float y)

(b) int sum(float a, int b)

(c) int sum(int x, int y)

(d) int sum(int x, float y)

 

         Correctanswer is   (c)

         8.  

         Whichis a Java access modifier used to designate that a particular data field willnot be inherited by a subclass?

(a) private

(b) final

(c) protected

(d) default

 

         Correctanswer is   (a)

         9.  

         Fromwithin a child class, its parent class is referred to via the keyword

(a) parent

(b) base

(c) this

(d) super

 

         Correctanswer is   (d)

         10.

         Whena subclass defines an instance method with the same return type and signatureas a method in its parent, the parent's method is said to be      

 

(a) private

(b) overridden

(c) overloaded

(d) hidden

 

         Correctanswer is   (b)

         2.  

         Ifa class contains a constructor, that constructor will be invoked       

 

(a) each time an object of that class isinstantiated

(b) once at the beginning of any programthat uses that class

(c) each time an object of that class goesout of scope

(d) once the first time an object of thatclass is instantiated

 

         Correctanswer is   (a)

         3.  

         Theterm class variable is a synonym for       

 

(a) a read-only variable

(b) a private data field

(c) an instance variable

(d) a static data field

 

         Correctanswer is   (d)

         5.

Which of the following categorizations canbe applied to both the data fields and the methods in a Java class?

(a) native and non-native

(b) abstract and non-abstract

(c) static and non-static

(d) default and non-default

 

         Correctanswer is   (c)

         9.  

Consider the following Java classdefinitions.

 

   public class Object1 {

     

       protected String d(){

           return "Hi";

       }

    }

 

   public class Object2 extends Object1 {

           

       protected String d(){

                      

           return super.d();

       }

    }

 

Which of the following statements is (are) trueregarding the definitions?

   1.Class Object2 inherits from class Object1.

   2.Class Object2 overrides method d.

   3.Method d returns equivalent results when executed from either class.

(a) I and III only

(b) I, II, and III

(c) I and II only

(d) III only

 

         Correctanswer is   (b)