Java Multiple Choice Questions & Answers on Methods Taking Parameters for Freshers

1. Which of these is the method which is executed first before execution of any other thing takes place in a program?

a) main method
b) finalize method
c) static method
d) private method

Answer: c

Explanation: If a static method is present in the program then it will be executed first, then main will be executed.
2. What is the process of defining more than one method in a class differentiated by parameters?

a) Function overriding
b) Function overloading
c) Function doubling
d) None of these
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 these can be used to differentiate two or more methods having same name?

a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned
Answer: d
4. Which of these data type can be used for a method having a return statement in it?

a) void
b) int
c) float
d) both int and float
Answer: d
5. Which of these statement is incorrect?

a) Two or more methods with same name can be differentiated on the basis of their parameters data type.
b) Two or more method having same name can be differentiated on basis of number of parameters.
c) Any already defined method in java’s library can be defined again in the program with different data type of parameters.
d) If a method is returning a value the calling statement must have a variable to store that value.
Answer: d

Explanation: Even if a method is returning a value, it is not necessary to store that value.
6. What is the output of this program?
  1.     class box {
  2.         int width;
  3.         int height;
  4.         int length;
  5.         int volume;
  6.         void volume(int height, int length, int width) {
  7.              volume = width * height * length;
  8.         } 
  9.     }    
  10.     class Prameterized_method{
  11.         public static void main(String args[]) {
  12.             box obj = new box();
  13.             obj.height = 1;
  14.             obj.length = 5;
  15.             obj.width = 5;
  16.             obj.volume(3, 2, 1);
  17.             System.out.println(obj.volume);        
  18.         } 
  19.     }
a) 0
b) 1
c) 6
d) 25
Answer: c
7. What is the output of this program?
  1.     class equality {
  2.         int x;
  3.         int y;
  4.         boolean isequal(){
  5.             return(x == y);  
  6.         } 
  7.     }    
  8.     class Output {
  9.         public static void main(String args[]) {
  10.             equality obj = new equality();
  11.             obj.x = 5;
  12.             obj.y = 5;
  13.             System.out.println(obj.isequal);
  14.         } 
  15.     }
a) false
b) true
c) 0
d) 1
Answer: b
8. What is the output of this program?
  1.     class box {
  2.         int width;
  3.         int height;
  4.         int length;
  5.         int volume;
  6.         void volume() {
  7.             volume = width * height * length;
  8.         } 
  9.         void volume(int x) {
  10.             volume = x;
  11.         }
  12.     }    
  13.     class Output { 
  14.         public static void main(String args[]) {
  15.             box obj = new box();
  16.             obj.height = 1;
  17.             obj.length = 5;
  18.             obj.width = 5;
  19.             obj.volume(5);
  20.             System.out.println(obj.volume);        
  21.         } 
  22.     }
a) 0
b) 5
c) 25
d) 26
Answer:b
9. What is the output of this program?
  1.     class Output {
  2.         static void main(String args[]) 
  3.         {    
  4.              int x , y = 1;
  5.              x = 10;
  6.              if(x != 10 && x / 0 == 0)
  7.                  System.out.println(y);
  8.              else
  9.                  System.out.println(++y);
  10.         } 
  11.     }
a) 1
b) 2
c) Runtime Error
d) Compilation Error
Answer: d

Explanation: main() method must be made public. Without main() being public java run time system will not be able to access main() and will not be able to execute the code.
10. What is the output of this program?
  1.     class area {
  2.         int width;
  3.         int length;
  4.         int height;
  5.         area() {
  6.         width = 5;
  7.         length = 6;
  8.         height = 1;
  9.         }
  10.         void volume() {
  11.              volume = width * height * length;
  12.         } 
  13.     }    
  14.     class cons_method {
  15.         public static void main(String args[]) {
  16.             area obj = new area();
  17.             obj.volume();
  18.             System.out.println(obj.volume);
  19.         } 
  20.     }
a) 0
b) 1
c) 25
d) 30
Answer: d

Related

Linux Questions & Answers on Linux Commands for Freshers -1

1. The dmesg command a) Shows user login logoff attemptsb) Shows the syslog file for info messagesc) kernel log messagesd) Shows the daemon log messages Answer: c 2. The command “mknod myfifo b 4...

C# Questions & Answers on Introduction of Indexers for Freshers

1. Choose the correct statement among the followings? a) Indexers are location indicatorsb) Indexers are used to access class objectsc) Indexer is a form of property and works in the same way as a ...

Linux Questions & Answers on Linux Environment for Freshers

1. To increase the response time and throughput, the kernel minimizes the frequency of disk access by keeping a pool of internal data buffer called a) Poolingb) Spoolingc) Buffer cached) Swapping ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item