Preview

11 - Recursion Sorting and Searching

 1. A class is a blueprint from which individual objects are created.
public class Dog {
   String breed;
   int age;
   String color;

   void barking() {
   }

   void hungry() {
   }

   void sleeping() {
   }
}
java_class_into_question_intermediate_1.jpg

  FALSE

  TRUE

 2. In the above example, barking(), hungry() and sleeping() are _________.

 3. Programmers use ______ to represent a physical object or nonphysical concept, real or imagined, by defining a class.

  variables

  strings

  code

  computers

 4. A class is defined based on the ______________________of the object or concept.

  errors / mistakes

  attributes and/or behaviors

  variables / strings

  syntax / lexical notations

 5. In the below code, 'name' and 'cell' are both:
private String name;
private String cell;

  constructors

  cells

  classes

  fields

 6. The keywords public and private affect the ______ of classes, data, constructors, and methods.

  deconstruction

  creation

  access

  deletion

 7. Fields are also called i__________ variables or object variables or properties.

  iteration

  intuitive

  instance

  instantiated

 8. On what line(s) are the field declarations in the below code?
public class Name {
    private String first;
    private String last;

    public Name(String theFirst, String theLast) {
        first = theFirst;
        last = theLast;
     }

     public void setFirst(String theFirst) {
        first = theFirst;
     }

     public void setLast(String theLast) {
        first = theLast;
     }

}

  line 5 and 6

  line 1 and 2

  line 2 and 3

  There are no explicit field declarations

 9. The keyword private _____________ to the declaring class, while the keyword public allows access from classes outside the declaring class.

  allows complete access

  defines public variables

  restricts variables from being created

  restricts access

 10. Access to attributes should be kept internal to the class. Therefore, instance variables are designated as ____________.

 11. Access to behaviors can be internal or external to the class. Therefore, _________ can be designated as either public or private.

 12. ________ hold the data for an object. _________ record what an object needs to know to do work in the program. ________ are also called instance variables or object variables or properties.

 13. Setting something to private is comparable to the access rights you may have on your _________________. Only you should have direct access to it.

  local road

  personal diary

  internet connection

  telephone directory

 14. Fields are declared ______________________.They start with private then the type of the field and then a name for the field.

  right after the class declaration.

  at the very top of the whole program

  just before the class declaration

  in between the call to the main program and the class declaration

 15. The following line would ask the _______ to load all the classes available in directory java_installation/java/io ?
import java.io.*;

  compiler

  byte sequence

  source code

  programmer

 16. How many instance variables can you count in the below code?
import java.io.*;
public class Employee {

   String name;
   int age;
   String designation;
   double salary;

   // This is the constructor of the class Employee
   public Employee(String name) {
      this.name = name;
   }

   // Assign the age of the Employee  to the variable age.
   public void empAge(int empAge) {
      age = empAge;
   }

   /* Assign the designation to the variable designation.*/
   public void empDesignation(String empDesig) {
      designation = empDesig;
   }

   /* Assign the salary to the variable	salary.*/
   public void empSalary(double empSalary) {
      salary = empSalary;
   }

   /* Print the Employee details */
   public void printEmployee() {
      System.out.println("Name:"+ name );
      System.out.println("Age:" + age );
      System.out.println("Designation:" + designation );
      System.out.println("Salary:" + salary);
   }
}

  4

  1

  3

  2

 17. The above class has ____ explicitly defined constructor, which takes ___ parameter.

  two / two

  one / two

  two / one

  one / one

 18. Referring to the code above and the Employee class, and the below code, note that the below class creates _______________________________.
import java.io.*;
public class EmployeeTest {

   public static void main(String args[]) {
      /* Create two objects using constructor */
      Employee empOne = new Employee("James Smith");
      Employee empTwo = new Employee("Mary Anne");

      // Invoking methods for each object created
      empOne.empAge(26);
      empOne.empDesignation("Senior Software Engineer");
      empOne.empSalary(1000);
      empOne.printEmployee();

      empTwo.empAge(21);
      empTwo.empDesignation("Software Engineer");
      empTwo.empSalary(500);
      empTwo.printEmployee();
   }
}

  three instances of the class Employee and invokes the methods for just one object

  a single instance of the class Employee and invokes the methods for two objects

  one instance of the class Employee and invokes the methods for two different objects

  two instances of the class Employee and invokes the methods for each object.

 19. Constructors don?t actually construct the object. The class makes the object and then executes a constructor to ______________________________________.

  initialize the values of the methods (method variables)

   initialize the values of the fields (instance variables).

  initialize the constants in the program (constant values)

  finalize the values of the fields (method variables)

 20. Constructors are specified after the fields and before any methods. They typically start with _____________________________.

  public and then the name of the class.

  private and then the name of the class

  the name of the class and then public

  the name(s) of the fields and the name of the class followed by either public or private (usually private)