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.

  computers

  strings

  code

  variables

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

  errors / mistakes

  syntax / lexical notations

  attributes and/or behaviors

  variables / strings

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

  fields

  cells

  classes

  constructors

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

  deletion

  creation

  access

  deconstruction

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

  intuitive

  instance

  iteration

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

}

  There are no explicit field declarations

  line 1 and 2

  line 5 and 6

  line 2 and 3

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

  allows complete access

  restricts access

  restricts variables from being created

  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.

  telephone directory

  personal diary

  internet connection

  local road

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

  just before the class declaration

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

  at the very top of the whole program

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

  3

  4

  2

  1

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

  one / two

  two / one

  two / 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

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

  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 ______________________________________.

  finalize the values of the fields (method variables)

  initialize the constants in the program (constant values)

  initialize the values of the methods (method variables)

   initialize the values of the fields (instance variables).

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

  the name of the class and then public

  public and then the name of the class.

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

  private and then the name of the class