Java Classes And Methods

Related Topics:

Java Programming : Java Classes And Methods

This page consist of Java Classes and Methods Questions and Answers, Interview Questions. Pdf for Java Classes and Methods Questions is also available here.
1. What is the return type of a method that does not returns any value?
[A] int
[B] float
[C] void
[D] double

Answer: C. void

Explanation:

Return type of an method must be made void if it is not returning any value.
2. What is the process of defining more than one method in a class differentiated by method signature?
[A] Function overriding
[B] Function overloading
[C] Function doubling
[D] None of the mentioned

Answer: B. Function overloading

Explanation:

Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or arameters type and number. Example – int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.
3. Which of the following is a method having same name as that of it’s class?
[A] finalize
[B] delete
[C] class
[D] constructor

Answer: D. constructor

Explanation:

A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides.
4. Which method can be defined only once in a program?
[A] main method
[B] finalize method
[C] static method
[D] private method

Answer: A. main method

Explanation:

main() method can be defined only once in a program. Program execution begins from the main() method by java’s run time system.
5. Which of these statement is incorrect?
[A] All object of a class are allotted memory for the all the variables defined in the class.
[B] If a function is defined public it can be accessed by object of other class by inheritance.
[C] main() method must be made public.
[D] All object of a class are allotted memory for the methods defined in the class.

Answer: D. All object of a class are allotted memory for the methods defined in the class.

Explanation:

All object of class share a single copy of methods defined in a class, Methods are allotted memory only once.
6. Which of these class is super class of every class in Java?
[A] String class
[B] Object class
[C] Abstract class
[D] ArrayList class

Answer: B. Object class

Explanation:

Object class is super class of every class in Java
7. Which of these method of Object class can clone an object?
[A] Objectcopy()
[B] copy()
[C] Object clone()
[D] clone()

Answer: C. Object clone()

8. Which of these method of Object class is used to obtain class of an object at run time?
[A] get()
[B] void getclass()
[C] Class getclass()
[D] None of the mentioned

Answer: C. Class getclass()

9. Which of these keywords can be used to prevent inheritance of a class?
[A] super
[B] constant
[C] Class
[D] final

Answer: D. final

Explanation:

Declaring a class final implicitly declares all of its methods final, and makes the class inheritable.
10. Which of these keywords cannot be used for a class which has been declared final?
[A] abstract
[B] extends
[C] abstract and extends
[D] None of the mentioned

Answer: A. abstract

Explanation:

A abstract class is incomplete by itself and relies upon its subclasses to provide complete implementation.

Comments: (Your feedback is valuable to us)

Anjana vadaje 11 months ago Reply

nice


jaya kumar 1 year ago Reply

good

assdad 1 year ago

k k


bond chiwewe 1 year ago Reply

its ok please,


Gidraf Kungu 1 year ago Reply

good


yogesh rawat 1 year ago Reply

great


Debjit Rowdian Banerjee 1 year ago Reply

qqqqq


alpesh sakhanpara 1 year ago Reply

Fdghb


;