0

Method Overloading and Method Overriding

Description: Method Overloading and Method Overriding
Number of Questions: 15
Created by:
Tags: Method Overloading and Method Overriding Inheritance and Constructor Java/Oracle /C/C++ Java
Attempted 0/15 Correct 0 Score 0

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.


Correct Option: D
Explanation:

Protected method is accessible from inside the class and all the classes defined in the same package, where the class is defined itself.

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.


Correct Option: D
Explanation:

This is a false statement. There can only be one finally block for each try block. Since the statement is false about 'finally' block in Java, it is the correct alternative.

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


Correct Option: C
Explanation:

The readLine() method can be accessed by the object of a BufferedReader class. For example,  String str; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); str=br.readLine();

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)


Correct Option: D
Explanation:

The correct syntax of the replace() method is StringBuffer replace(int s,int e,String str) Replaces the characters in a substring of the given sequence with the given string 'str'.

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


Correct Option: C
Explanation:

The NumberFormat class belongs to java.text package. It has three methods that yield standard formats for numbers, currency values and percentage values.

__________ methods cannot be overriden in a subclass.

  1. Final

  2. Finally

  3. Public

  4. Protected


Correct Option: A
Explanation:

Final methods cannot be overriden in a subclass. If we try to override, then such action generates compile time error.

___________ method creates and returns a copy of an object.

  1. copy()

  2. clone()

  3. xcopy()

  4. copyObject()


Correct Option: B
Explanation:

The clone() method creates and returns a copy of an object.

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


Correct Option: B
Explanation:

This method of Process class in Java returns an input stream that reads input from the process out.

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


Correct Option: B
Explanation:

The finalize() method is called by the garbage collector when it determines that there are no more references to the object. The return type of finalize() method is protected void.

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


Correct Option: B
Explanation:

This method in SmashTransition class is used to modify the work_pixels array for the next cell in Java.

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


Correct Option: A
Explanation:

This character method in Java returns true value when argument provided with function is in uppercase letters.

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.


Correct Option: D
Explanation:

This is a false statement. Method overloading cannot be done by changing the return type of a method.

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


Correct Option: C
Explanation:

This method of Runtime class returns the approximate number of bytes of free memory available to the Java run-time system.

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


Correct Option: C
Explanation:

java.lang.StringBuffer is the only class in the list that uses the default methods provided by class Object.

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


Correct Option: A
Explanation:

This method in Integer class returns a string that contains the decimal equivalent of the invoking object.

- Hide questions