logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

Java Multiple Choice Questions | MCQs | Quiz

Java Interview Questions and Answers
Pratice Java questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Floating Data Types
•   Character Data Types
•   Enums Data Types
•   BigDecimal Data Types
•   Date & TimeZone
•   Literals & Variables
•   Type Conversion & Castings
•   Arrays
•   Data Structures - Arrays
•   Arithmetic Operators
•   Bitwise Operators
•   Relational Operators
•   Assignment Operators
•   Control Statements - 1
•   Control Statements - 2
•   OOPS Concepts
•   JDK, JRE, JIT & JVM
•   Class Fundamentals
•   Methods Basics
•   Garbage Collection
•   Constructors
•   Heap & Garbage Collection
•   Overloading Methods
•   Access Control - 1
•   Access Control - 2
•   Static Keyword
•   String Class
•   Methods Taking Parameters
•   Command Line Arguments1
•   Command Line Arguments2
•   Recursion
•   Method Overriding
•   Object Class
•   Abstract Class & Super
•   Inheritance - 1
•   Inheritance - 2
•   String Handling Basics
•   Character Extraction
•   String Comparison
•   String Searching
•   StringBuffer Class
•   StringBuffer Methods
•   ↓ Java.lang ↓
•   Java.lang Basics
•   Long & Character Wrappers
•   Process & System Class
•   Object & Math Class
•   System Class Advance
•   Double & Float Wrappers
•   Java.io Basics
•   Java.io Byte Streams
•   Java.io Character Streams
•   Memory Management
•   Builtin Exceptions
•   Rounding Functions
•   Byte & Short Wrappers
•   Character Wrapper Advance
•   Boolean Wrapper Advance
•   StrictMath Class
•   Runtime Classes
•   Java.lang - Class
•   ThreadGroup Class
•   Environment Properties
•   Serialization - 1
•   Serialization - 2
•   Deserialization
•   Networking Basics
•   Sockets & httpd Class
•   Networking-httpd.java Class
•   URL Class
•   URLConnection Class
•   Networking - Datagrams
•   Java.util - ArrayList Class
•   Data Structures - HashMap
•   Data Structures - List
•   Data Structures - Set
•   ↓ Java.util ↓
•   LinkedList & HashSet Class
•   Java.util - Maps
•   Vectors & Stack
•   Hashtable & Properties
•   BitSet & Date class
•   Remote Method Invocation
•   Collection Framework
•   Iterators
•   Data Structures - Queue
•   Java.util - Array Class
•   Collections Interface
•   Collection Algorithms
•   Basic Exceptional Handling
•   Exceptional Handling
•   Exceptions Types
•   Throw, Throws & Nested Try
•   Finally & Builtin Exceptions
•   Try & Catch
•   Creating Exceptions
•   Thread Synchronization
•   Threads Implementation
•   Thread Class
•   Multithreading Basics
•   Multithreading
•   Creating Threads
•   Input & Output Basics
•   Reading Console Input
•   Writing Console Output
•   Reading & Writing Files
•   Applets Fundamentals
•   Text Formatting
•   Regular Expression
•   Event Handling Basics
•   AdjustmentEvent Class
•   ComponentEvent Class
•   MouseEvent & TextEvent
•   Event Listeners Interfaces
•   Random Number
•   Locale & Random Classes
•   Observable & Timer Class
•   Packages
•   Interfaces - 1
•   Interfaces - 2
•   Core Java API Packages
•   Interface Types
•   JUnits
•   Java 8 Features
•   File & Directory
•   Hibernate
•   Liskovs Principle
•   Coding Best Practices
•   Generics
•   Generic Methods
•   Generics Restrictions
•   Wildcards
•   Java Beans
•   JDBC
•   Design Patterns
•   Eclipse Debugging
•   Web Application
•   Client & Server
•   Servlet
•   Session Management
•   JSP
•   JSP Elements
•   Reflection API
•   AutoCloseable Interfaces
•   Ant, Maven & Jenkins
•   Annotations

Best Reference Books

Java Books
« Prev Page
Next Page »

Java Questions & Answers – Introduction To Methods

Posted on March 31, 2017 by Manish

This section of our 1000+ Java MCQs focuses on Methods of Java Programming Language.

1. What is the return type of a method that does not returns any value?
a) int
b) float
c) void
d) double
View Answer

Answer: c
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
View Answer

Answer: b
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 parameters 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
View Answer

Answer: d
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
View Answer

Answer: a
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 inheritation
c) main() method must be made public
d) All object of a class are allotted memory for the methods defined in the class
View Answer

Answer: d
Explanation: All object of class share a single copy of methods defined in a class, Methods are allotted memory only once. All the objects of the class have access to methods of that class are allotted memory only for the variables not for the methods.

6. What is the output of this program?

  1.     class box 
  2.     {
  3.         int width;
  4.         int height;
  5.         int length;
  6.         int volume;
  7.         void volume(int height, int length, int width) 
  8.         {
  9.              volume = width*height*length;
  10.         } 
  11.     }    
  12.     class Prameterized_method
  13.     {
  14.         public static void main(String args[])
  15.         {
  16.             box obj = new box();
  17.             obj.height = 1;
  18.             obj.length = 5;
  19.             obj.width = 5;
  20.             obj.volume(3,2,1);
  21.             System.out.println(obj.volume);        
  22.         } 
  23.      }

a) 0
b) 1
c) 6
d) 25
View Answer

Answer: c
Explanation: None.
output:
$ Prameterized_method.java
$ Prameterized_method
6

7. What is the output of this program?

  1.     class equality 
  2.     {
  3.         int x;
  4.         int y;
  5.         boolean isequal()
  6.         {
  7.             return(x == y);  
  8.         } 
  9.     }    
  10.     class Output 
  11.     {
  12.         public static void main(String args[])
  13.         {
  14.             equality obj = new equality();
  15.             obj.x = 5;
  16.             obj.y = 5;
  17.             System.out.println(obj.isequal());
  18.         } 
  19.     }

a) false
b) true
c) 0
d) 1
View Answer

Answer: b
Explanation: None.
output:
$ javac Output.java
$ java Output
true

8. What is the output of this program?

  1.     class box 
  2.     {
  3.         int width;
  4.         int height;
  5.         int length;
  6.         int volume;
  7.         void volume() 
  8.         {
  9.              volume = width*height*length;
  10.         } 
  11.     }    
  12.     class Output 
  13.     { 
  14.         public static void main(String args[])
  15.         {
  16.             box obj = new box();
  17.             obj.height = 1;
  18.             obj.length = 5;
  19.             obj.width = 5;
  20.             obj.volume();
  21.             System.out.println(obj.volume);        
  22.         } 
  23.     }

a) 0
b) 1
c) 25
d) 26
View Answer

Answer:c
Explanation: None.
output:
$ javac Output.java
$ java Output
25

9. In the below code, which call to sum() method is appropriate?

  1. class Output 
  2. {
  3.  
  4.         public static int sum(int ...x)
  5.         {
  6.              return; 
  7.         }
  8.         static void main(String args[]) 
  9.         {    
  10.              sum(10);
  11.              sum(10,20);
  12.              sum(10,20,30);
  13.              sum(10,20,30,40);
  14.         } 
  15. }

a) only sum(10)
b) only sum(10,20)
c) only sum(10) & sum(10,20)
d) all of the mentioned
View Answer

Answer: d
Explanation: sum is a variable argument method and hence it can take any number as argument.

10. What is the output of this program?

  1.     class area 
  2.     {
  3.         int width;
  4.         int length;
  5.         int volume;
  6.         area() 
  7.         {
  8.            width=5;
  9.            length=6;
  10.         }
  11.         void volume() 
  12.         {
  13.              volume = width*length*height;
  14.         } 
  15.     }    
  16.     class cons_method 
  17.     {
  18.         public static void main(String args[])
  19.         {
  20.             area obj = new area();
  21.             obj.volume();
  22.             System.out.println(obj.volume);        
  23.         } 
  24.     }

a) 0
b) 1
c) 30
d) error
View Answer

Answer: d
Explanation: Variable height is not defined.
output:
$ javac cons_method.java
$ java cons_method
error: cannot find symbol height
Sanfoundry Global Education & Learning Series – Java Programming Language.

Here’s the list of Best Reference Books in Java Programming Language.

To practice all features of Java programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.

« Prev Page - Java Questions & Answers – Class Fundamentals & Declaring objects
» Next Page - Java Questions & Answers – Constructors & Garbage Collection
« Java Questions & Answers – Class Fundamentals & Declaring objects
Java Questions & Answers – Constructors & Garbage Collection »

Deep Dive @ Sanfoundry:

  1. 100+ Java Android Programming Examples
  2. Java Programming Examples on Graph Problems & Algorithms
  3. Java Questions and Answers
  4. Java Programming Examples on Combinatorial Problems & Algorithms
  5. Java Algorithms, Problems & Programming Examples
  6. Java Programming Examples on Numerical Problems & Algorithms
  7. Java Programming Examples on Data-Structures
  8. Java Programming Examples on Hard Graph Problems & Algorithms
  9. Java Programming Examples on Collection API
  10. Java Programming Examples on Computational Geometry Problems & Algorithms
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry