J2EEOnline J2EE   





Java Questions 21 - 30  «Prev  Next»

Java Questions 21

  1. What is the purpose of the keyword strictfp?
    Answer:
    strictfp forces floating points to adhere to the IEEE 754 standard.
    The keyword strictfp can only be used with classes, interfaces and non-abstract methods.
  2. What can strictfp modify?
    Answer:
    stictfp can modify 1) class or 2) non-abstract method declarations. A variable (such as a primitive int) can never be declared strictfp.
  3. What is the purpose of Java var-args syntax?
    Answer:
    The purpose of Java var-args is to allow you to create methods that can take a variable number of arguments.
  4. What is the name of the elements that you specify between the parentheses when you are invoking a method?
    Answer:
    These are known as arguments.
    The "method call" below contains two arguments:
     getSalary("name", age);
     
  5. What are the elements in the method's signature that indicate what the method must receive when the method is called?
    Answer:
    These are known as parameters. The method declaration below contains 2 parameters.
    Employee getSalary (String name, int age) {} 
    
  6. Where does the "var-arg" parameter appear in a method declaration?
    Answer:
    In a method declaration, the var-arg must appear last.
    static int sum (int ... numbers){
     int total = 0;
      for (int i = 0; i < numbers.length; i++)
       total += numbers [i];
      return total;
    }
    
  7. What happens every time a new object is created?
    Answer:
    Everytime you make a new object, at least one constructor is invoked.
  8. When does the default "no-args" constructor get created?
    Answer:
    When you do not explicitly provide a constructor, the compiler will create a default "no-args" constructor.
  9. Do constructors have a reutrn type?
    Answer:
    No. Constructors do not have a return type and only methods have a return type.
  10. What type of access modifiers can constructors have?
    Answer:
    Constructors can have the standard access modifiers,
    public, protected, default, private.