DigitalMag

Анонимные классы Java

Apr 10th, 2020
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. class BroadcastReceiver{
  2.     public void onReceive() {
  3.    
  4.         System.out.println("abstract");
  5.     }
  6. }
  7.  
  8. public class Main
  9.     {
  10.     public static void main(String[] args) {
  11.    
  12.         BroadcastReceiver ex0 = new BroadcastReceiver();
  13.         BroadcastReceiver ex1 = new BroadcastReceiver(){};
  14.         BroadcastReceiver ex = new BroadcastReceiver(){
  15.             @Override
  16.             public void onReceive() {
  17.            
  18.                 System.out.println("BroadcastReceiver : onReceive");
  19.             }
  20.         };
  21.    
  22.         System.out.println(ex0.getClass() == BroadcastReceiver.class);
  23.        
  24.         System.out.println(ex0.getClass() == ex1.getClass());
  25.        
  26.         System.out.println(ex.getClass() == BroadcastReceiver.class);
  27.        
  28.         System.out.println(ex.getClass());
  29.        
  30.         System.out.println(BroadcastReceiver.class);
  31.        
  32.         System.out.println(ex instanceof Object);
  33.     }
  34. }
Add Comment
Please, Sign In to add comment