Languages-Java [3i Infotech Placement]: Sample Questions 90 - 92 of 141

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 90

Question

MCQ▾

What is the output of following block of program?

  1. booleanvar =false.
  2. if (var =true)
  3. {
  4.     System. Out. Println ( “TRUE” );
  5. }
  6. else
  7. {
  8.     System. Out. Println ( “FALSE” );
  9. }

Choices

Choice (4)

a.

Run-time Error

b.

True

c.

Compilation Error

d.

False

Answer

b.

Explanation

Table of Block of Program
Boolean var = falseDeclares boolean variable is false
If (var = true)If variable is true
  1. {
  2.     System. Out. Println ( “TRUE” );
  3. }
Print true. Because variable is set to true in the if argument this command is executed
else
  1. {
  2.     System. Out. Println ( “FALSE” );
  3. }
Otherwise print false. The else part is not executed

Question 91

Edit

Write in Short

Short Answer▾

What must a class do to implement an interface?

Explanation

  • Provide definitions for methods in the interface and identify the interface in its implements clause.
  • A class can implement more than one interface.
  • Implements keyword is followed by a comma-separated list of the interfaces implemented by the class.

Question 92

Edit

Write in Short

Short Answer▾

Does java support multiple inheritances? If not, what is the solution?

Explanation

  • No, java does not support multiple inheritance as it creates confusion and complexity when both extended class have the same method name leading to ambiguity in executing.
  • Java interface works similar to the multiple inheritances.
  • Interface provides flexibility with option to implement multiple interfaces using single class.
  • In interfaces, methods are defined in the child classes avoiding ambiguity.

Developed by: