fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. class GenericClass<T,U>
  10. {
  11. public T id;
  12. public U name;
  13. GenericClass(T id, U name)
  14. {
  15. this.id = id;
  16. this.name = name;
  17. }
  18.  
  19. public static <E>
  20. E add(E n1, E n2)
  21. {
  22.  
  23. System.out.println(n1);
  24. return n2;
  25. }
  26. }
  27.  
  28. class Ideone
  29. {
  30. public static void mergesort(int arr[])
  31. {
  32. int size = arr.length;
  33. if(size <2)
  34. return;
  35.  
  36. int middle = size/2;
  37. int index =0;
  38.  
  39. int left[] = new int[middle];
  40. for(index =0;index<middle;index++)
  41. left[index] = arr[index];
  42.  
  43. int right[] = new int[size- middle];
  44. for(int i=0;index<size;i++,index++)
  45. right[i]=arr[index];
  46.  
  47. mergesort(left);
  48. mergesort(right);
  49. merge_arrays(left,right,arr);
  50. }
  51.  
  52. public static void merge_arrays(int[] left, int right[], int arr[])
  53. {
  54. int l=0,r=0,index=0;
  55.  
  56. while(l<left.length && r<right.length)
  57. {
  58. if(left[l] < right[r])
  59. {
  60. arr[index]= left[l];
  61. index++;
  62. l++;
  63. }
  64. else
  65. {
  66. arr[index]= right[r];
  67. index++;
  68. r++;
  69. }
  70. }
  71.  
  72. while(l<left.length)
  73. {
  74. arr[index++]=left[l++];
  75. }
  76. while(r<right.length)
  77. {
  78. arr[index++]= right[r++];
  79. }
  80.  
  81. }
  82.  
  83. public static void bubblesort(int[] arr)
  84. {
  85. boolean flag= true;
  86.  
  87. while(flag)
  88. {
  89. flag = false;
  90. for(int j=0;j<arr.length -1;j++)
  91. {
  92. if(arr[j+1]<arr[j])
  93. {
  94. int temp = arr[j+1];
  95. arr[j+1]=arr[j];
  96. arr[j]=temp;
  97. flag = true;
  98. }
  99. }
  100. }
  101. }
  102. class Check
  103. {
  104. public int data;
  105.  
  106. }
  107. public static void main (String[] args) throws java.lang.Exception
  108. {
  109. Check obj1 = new Check();
  110. obj1.data =1;
  111. Check obj2 = new Check();
  112. obj2 = obj1;
  113. obj2.data =3;
  114. System.out.print(obj1.data);
  115. /* int arr[] = {3,2,4,5,1,7};
  116. bubblesort(arr);
  117. for(int i=0;i<arr.length;i++)
  118. System.out.print(arr[i]+" ");*/
  119. /*// your code goes here
  120. GenericClass<Integer,String> obj = new GenericClass<Integer,String>(2,"Atreya");
  121. System.out.println(obj.id+" "+obj.name);
  122.  
  123. GenericClass.add<Integer>(2.4,3);*/
  124. }
  125. }
Compilation error #stdin compilation error #stdout 0.07s 380160KB
stdin
Standard input is empty
compilation info
Main.java:109: error: non-static variable this cannot be referenced from a static context
		Check obj1 = new Check();
		             ^
Main.java:111: error: non-static variable this cannot be referenced from a static context
		Check obj2 = new Check();
		             ^
2 errors
stdout
Standard output is empty