Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.24 KB | None | 0 0
  1. public class C
  2. {
  3.     public static void myPrint(String ... names)
  4.     {
  5.         for (String n : names)
  6.         {
  7.             System.out.print(n);
  8.         }
  9.     }
  10.    
  11.     public static void main(String[]args)
  12.     {
  13.         myPrint();
  14.         myPrint("A");
  15.         myPrint("A" , "B");
  16.         myPrint("A" , "B" , "C");
  17.        
  18.         // OPCJA 1
  19.         //A <String>a = new A<String>("jas");   //constructor A in class A<T> cannot be applied to given types
  20.         //A <int>b = new A<String>(1);          //unexpected type
  21.         //A <Double>c = new A<Double>(1.1);     //constructor A in class A<T> cannot be applied to given types  
  22.         //A <double>d = new A<double>(1.1);     //unexpected type
  23.         //A <int>e = new A<int>(1);             //unexpected type
  24.        
  25.         A <String>a = new A<String>("jas");
  26.         //A <int>b = new A<String>(1);          //unexpected type
  27.         A <Double>c = new A<Double>(1.1);      
  28.         //A <double>d = new A<double>(1.1);     //unexpected type
  29.         //A <int>e = new A<int>(1);             //unexpected type
  30.        
  31.     }
  32. }
  33.  
  34. // OPCJA 1
  35. //class A<T>{ }
  36.  
  37. //OPCJA 2
  38. class A<T>{
  39.     T t;
  40.     public A(T a)
  41.     {
  42.         t = a;
  43.         System.out.println(t);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement