Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.


What is the output of this program?


interface calculate {
int VAR = 0;
void cal(int item);
}
class display implements calculate {
int x;
public void cal(int item) {
if (item
  1.    0 1 2
  2.    0 2 4
  3.    0 0 4
  4.    0 1 4
 Discuss Question
Answer: Option C. -> 0 0 4

None.
output:
$ javac interfaces.java
$ java interfaces
0 0 4


Question 2.


What is the output of this program?


interface calculate {
void cal(int item);
}
class displayA implements calculate {
int x;
public void cal(int item) {
x = item * item;
}
}
class displayB implements calculate {
int x;
public void cal(int item) {
x = item / item;
}
}
class interfaces {
public static void main(String args[]) {
displayA arr1 = new displayA;
displayB arr2 = new displayB;
arr1.x = 0;
arr2.x = 0;
arr1.cal(2);
arr2.cal(2);
System.out.print(arr1.x + " " + arr2.x);
}
}
  1.    0 0
  2.    2 2
  3.    4 1
  4.    1 4
 Discuss Question
Answer: Option C. -> 4 1

class displayA implements the interface calculate by doubling the value of item, where as 

class displayB implements the interface by dividing item by item, therefore variable x of 

class displayA stores 4 and variable x of class displayB stores 1.
Output:
$ javac interfaces.java
$ java interfaces
4 1


Question 3.


What is the output of this program?


interface calculate {
void cal(int item);
}
class display implements calculate {
int x;
public void cal(int item) {
x = item * item;
}
}
class interfaces {
public static void main(String args[]) {
display arr = new display;
arr.x = 0;
arr.cal(2);
System.out.print(arr.x);
}
}
  1.    0
  2.    2
  3.    4
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> 4

None.
Output:
$ javac interfaces.java
$ java interfaces
4


Question 4.

Which of the following package stores all the standard java classes?


  1.    lang
  2.    java
  3.    util
  4.    java.packages
 Discuss Question
Answer: Option B. -> java

None.


Question 5.

Which of the following is incorrect statement about packages?


  1.    Interfaces specifies what class must do but not how it does.
  2.    Interfaces are specified public if they are to be accessed by any code in the program.
  3.    All variables in interface are implicitly final and static.
  4.    All variables are static and methods are public if interface is defined pubic.
 Discuss Question
Answer: Option D. -> All variables are static and methods are public if interface is defined pubic.

All methods and variables are implicitly public if interface is declared public.


Question 6.

Which of the following is correct way of implementing an interface salary by 

class manager?


  1.    class manager extends salary {}
  2.    class manager implements salary {}
  3.    class manager imports salary {}
  4.    None of the mentioned.
 Discuss Question
Answer: Option B. -> class manager implements salary {}

None.


Question 7.

Which of these can be used to fully abstract a class from its implementation?


  1.    Objects
  2.    Packages
  3.    Interfaces
  4.    None of the Mentioned.
 Discuss Question
Answer: Option C. -> Interfaces

None.


Question 8.

Which of these access specifiers can be used for an interface?


  1.    Public
  2.    Protected
  3.    private
  4.    All of the mentioned
 Discuss Question
Answer: Option A. -> Public

Access specifier of interface is either public or no specifier. When no access specifier is used 

then default access specifier is used due to which interface is available only to other members 

of the package in which it is declared, when declared public it can be used by any code.


Question 9.

Which of these keywords is used to define interfaces in Java?


  1.    interfac
  2.    Interface
  3.    intf
  4.    Intf
 Discuss Question
Answer: Option A. -> interfac

None.


Question 10.

Which of these keywords is used by a class to use an interface defined previously?


  1.    import
  2.    Import
  3.    implements
  4.    Implements
 Discuss Question
Answer: Option C. -> implements

interface is inherited by a class using implements.


Latest Videos

Latest Test Papers