Preview

11 - Recursive Searching Sorting

 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

  TRUE

  FALSE

 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.

  strings

  code

  variables

  computers

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

  errors / mistakes

  variables / strings

  syntax / lexical notations

  attributes and/or behaviors

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

  constructors

  fields

  cells

  classes

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

  creation

  access

  deconstruction

  deletion

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

  instantiated

  iteration

  instance

  intuitive

 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;
     }

}

  There are no explicit field declarations

  line 2 and 3

  line 1 and 2

  line 5 and 6

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

  restricts access

  restricts variables from being created

  allows complete access

  defines public variables

 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.

  internet connection

  local road

  telephone directory

  personal diary

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

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

  right after the class declaration.

  at the very top of the whole program

  just before 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.*;

  programmer

  compiler

  source code

  byte sequence

 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);
   }
}

  1

  4

  3

  2

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

  two / two

  two / one

  one / two

  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();
   }
}

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

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

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

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

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

  initialize the constants in the program (constant values)

  finalize the values of the fields (method variables)

   initialize the values of the fields (instance variables).

  initialize the values of the methods (method variables)

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

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

  the name of the class and then public

  private and then the name of the class

  public and then the name of the class.