Method Overloading and Method Overriding

Method Overloading and Method Overriding

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

If there is a protected method within the Public class, then which of the following statements is correct?

  1. Protected method does not access the public method.
  2. Method is accessible from inside a class and a subclasses.
  3. Protected method is not allowed within the Public class.
  4. Method is accessible from inside the class and all the classes defined in the same package, where the class is defined itself.
Question 2 Multiple Choice (Single Answer)

Which of the following statements regarding 'finally' block in Java is false?

  1. Before the termination of the program, JVM executes the 'finally' block (if any).
  2. The 'finally' block can be used for writing the cleanup code.
  3. The 'finally' block must be followed by try or catch block.
  4. There can be multiple 'finally' blocks for a try block.
  5. The 'finally' block is not executed if the program exists.
Question 3 Multiple Choice (Single Answer)

The method readLine() can be accessed by the object of a ____________ class to read a string from console.

  1. InputStreamReader
  2. InputStream
  3. BufferedReader
  4. StringReader
Question 4 Multiple Choice (Single Answer)

What is the correct syntax of replace() method of the StringBuffer class?

  1. StringBuffer replace(int s,int e)
  2. StringBuffer replace(int s,String str)
  3. StringBuffer replace(int s,String str1,String str2)
  4. StringBuffer replace(int s,int e,String str)
Question 5 Multiple Choice (Single Answer)

The methods of NumberFormat class are used to display the numbers in standard formats(Currency values and percentage values).The NumberFormat class belongs to which of the following packages?

  1. java.lang
  2. java.io
  3. java.text
  4. java.txt
Question 6 Multiple Choice (Single Answer)

__________ methods cannot be overriden in a subclass.

  1. Final
  2. Finally
  3. Public
  4. Protected
Question 7 Multiple Choice (Single Answer)

___________ method creates and returns a copy of an object.

  1. copy()
  2. clone()
  3. xcopy()
  4. copyObject()
Question 8 Multiple Choice (Single Answer)

Which of the following methods of Process class in Java returns an input stream that reads input from the process out?

  1. destroy()
  2. getInputStream()
  3. getErrorStream()
  4. getOutputStream()
  5. exitValue()
Question 9 Multiple Choice (Single Answer)

Which of the following methods is called by the garbage collector when it determines that there are no more references to the object?

  1. final()
  2. finalize()
  3. collector()
  4. collection()
Question 10 Multiple Choice (Single Answer)

Which of the following methods in SmashTransition class is used to modify the work_pixels array for the next cell in Java?

  1. init()
  2. smash()
  3. tear()
  4. sleep()
  5. run()
Question 11 Multiple Choice (Single Answer)

Which of the following character methods in Java returns true value when argument provided with function is in uppercase letters?

  1. isUpperCase()
  2. toUpperCase()
  3. toLowerCase()
  4. toTitleCase()
  5. isLetter()
Question 12 Multiple Choice (Single Answer)

Which of the following statements is false regarding method overloading?

  1. When a class has multiple methods with the same name but different input parameters, then such methods are considered to be overloaded.
  2. Method overloading increases the readability of a program.
  3. Method overloading can be done by changing the number of input parameters.
  4. Method overloading can be done by changing the return type of method.
  5. Main() method can be overloaded.
Question 13 Multiple Choice (Single Answer)

Which of the following methods of Runtime class returns the approximate number of bytes of free memory available to the Java run-time system?

  1. gc()
  2. getRuntime()
  3. freeMemory()
  4. halt()
  5. totalMemory()
Question 14 Multiple Choice (Single Answer)

Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

  1. java.lang.String
  2. java.lang.Double
  3. java.lang.StringBuffer
  4. java.lang.Character
Question 15 Multiple Choice (Single Answer)

Which of the following methods in Integer class returns a string that contains the decimal equivalent of the invoking object?

  1. toString()
  2. toBinaryString()
  3. shortValue()
  4. parseInt()
  5. hashCode()