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

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

    import

    Import

    implements

    Implements

Next Question

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

Check Answer

More TNPSC Videos
EasyTutorial Youtube Channel

***************************MCQS ONINTERFACE**********************1. Which of these keywords is used to define interfaces in Java?A. interfaceB. InterfaceC. intfD. Intf

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

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

D. All of the mentioned4. Which of these keywords is used by a class to use an interface defined previously?

5. Which of the following is correct way of implementing an interface salary by class manager?A. class manager extends salary {}B. class manager implements salary {}C. class manager imports salary {}D. None of the mentioned.

6. Which of the following is incorrect statement about packages?

B. Interfaces are specified public if they are to be accessed by any code in the program.C. All variables in interface are implicitly final and static.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.7. Which of the following package stores all the standard java classes?

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

9. Which of these can be used to fully abstract a class from its implementation?a] Objects

b] Packagesc] Interfacesd] None of the Mentioned.

Java MCQs on interfaces of Java Programming Language.

1. Which of these keywords is used to define interfaces in Java?
a] interface
b] Interface
c] intf
d] Intf

Answer: a
Clarification: None.

2. Which of these can be used to fully abstract a class from its implementation?
a] Objects
b] Packages
c] Interfaces
d] None of the Mentioned

Answer: c
Clarification: None.

3. Which of these access specifiers can be used for an interface?
a] Public
b] Protected
c] private
d] All of the mentioned

Answer: a
Clarification: Access specifier of an 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.

4. Which of these keywords is used by a class to use an interface defined previously?
a] import
b] Import
c] implements
d] Implements

Answer: c
Clarification: interface is inherited by a class using implements.

5. Which of the following is the correct way of implementing an interface salary by class manager?
a] class manager extends salary {}
b] class manager implements salary {}
c] class manager imports salary {}
d] none of the mentioned

Answer: b
Clarification: None.

6. Which of the following is an incorrect statement about packages?
a] Interfaces specifies what class must do but not how it does
b] Interfaces are specified public if they are to be accessed by any code in the program
c] All variables in interface are implicitly final and static
d] All variables are static and methods are public if interface is defined pubic

Answer: d
Clarification: All methods and variables are implicitly public if interface is declared public.

7. What will be the output of the following Java program?

  1.     interface calculate
  2.     {
  3.         void cal[int item];
  4.     }
  5.     class display implements calculate
  6.     {
  7.         int x;
  8.         public void cal[int item]
  9.         {
  10.             x = item * item;            
  11.         }
  12.     }
  13.     class interfaces
  14.     {
  15.         public static void main[String args[]]
  16.         {
  17.             display arr = new display;
  18.             arr.x = 0;      
  19.             arr.cal[2];
  20.             System.out.print[arr.x];
  21.         }
  22.     }

a] 0
b] 2
c] 4
d] None of the mentioned

Answer: c
Clarification: None.
Output:

$ javac interfaces.java
$ java interfaces
4

8. What will be the output of the following Java program?

  1.     interface calculate
  2.     {
  3.         void cal[int item];
  4.     }
  5.     class displayA implements calculate
  6.     {
  7.         int x;
  8.         public void cal[int item]
  9.         {
  10.             x = item * item;            
  11.         }
  12.     }
  13.     class displayB implements calculate
  14.     {
  15.         int x;
  16.         public void cal[int item]
  17.         {
  18.             x = item / item;            
  19.         }
  20.     }
  21.     class interfaces 
  22.     {
  23.         public static void main[String args[]]
  24.         {
  25.             displayA arr1 = new displayA;
  26.             displayB arr2 = new displayB;
  27.             arr1.x = 0;
  28.             arr2.x = 0;      
  29.             arr1.cal[2];
  30.             arr2.cal[2];
  31.             System.out.print[arr1.x + " " + arr2.x];
  32.         }
  33.     }

a] 0 0
b] 2 2
c] 4 1
d] 1 4

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

9. What will be the output of the following Java program?

  1. interface calculate 
  2. {
  3.             int VAR = 0;
  4.             void cal[int item];
  5. }
  6.         class display implements calculate 
  7.         {
  8.             int x;
  9.           public  void cal[int item]
  10.           {
  11.                 if [item

Chủ Đề