Which of these methods initiates garbage collection?
Which of the following is the correct way to import an entire package 'pkg'?
class outputs
{
public static void main(String args[])
{
int arr[] = new int [10];
System.out.print(arr);
}
}
class variable_scope
{
public static void main(String args[])
{
int a;
a= 15;
{
int b = 16;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}
Predict the output of the following Java code:
public class Abekus {
int i = 100;
public void method(int i) { this.i = i + i * 6; }
public void display() { System.out.println(i); }
public static void main(String[] args) {
Abekus o = new Abekus();
o.method(10);
o.display();
}
}
class jj{
public static void main(String args[]){
String str="My name is shubham Kumar rai";
String [] temp =str.split(" ");
StringBuilder sb=new StringBuilder();
for(int i=temp.length-1;i>=0;i--){
sb.append(temp[i]+" ");
}
System.out.println(sb);
}
}
class outputs
{
public static void main(String args[])
{
int arr[][] = { {1, 2, 3}, {4 , 5, 6},{ 7, 8, 9} };
int result = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3 ; ++j)
result = result + arr[i][j];
System.out.print(result /5);
}
}
How to make a read-only class in Java?
import java.util.*;
class output
{
public static void main(String args[])
{
LinkedList set = new LinkedList();
set.add(new Integer(3));
set.add(new Integer(8));
set.add(new Integer(5));
set.add(new Integer(1));
set.addFirst(new Integer(2));
set.addLast(new Integer(9));
Iterator i = set.iterator();
Collections.reverse(set);
Collections.shuffle(set);
System.out.println(set.pollFirst()+" "+set.pollLast());
}
}