Question 41
1 public class While 2 { 3 public void loop() 4 { 5 int x = 0; 6 while(1) 7 { 8 System.out.println("x plus one is" +(x+1)); 9 } 10 } 11 }
Question 42
program side-effect (input, output); var x, result: integer; function f (var x:integer):integer; begin x:x+1;f:=x; end; begin x:=5; result:=f(x)*f(x); writeln(result); end;
Question 43
class Test
{
public void demo(String str)
{
String[] arr = str.split(\";\");
for (String s : arr)
{
System.out.println(s);
}
}
public static void main(String[] args)
{
char array[] = {\'a\', \'b\', \' \', \'c\', \'d\', \';\', \'e\', \'f\', \' \',
\'g\', \'h\', \';\', \'i\', \'j\', \' \', \'k\', \'l\'};
String str = new String(array);
Test obj = new Test();
obj.demo(str);
}
}
Question 44
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println(\"i = \" + i + \", j = \" + j);
}
}
Question 46
class Main {
public static void main(String args[]){
final int i;
i = 20;
System.out.println(i);
}
}
Question 47
class Main {
public static void main(String args[]){
final int i;
i = 20;
i = 30;
System.out.println(i);
}
}
Question 48
class Base {
public final void show() {
System.out.println(\"Base::show() called\");
}
}
class Derived extends Base {
public void show() {
System.out.println(\"Derived::show() called\");
}
}
public class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
Question 49
class T {
int t = 20;
T() {
t = 40;
}
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}
Question 50
Which of the following is true about interfaces in java.
1) An interface can contain following type of members. ....public, static, final fields (i.e., constants) ....default and static methods with bodies 2) An instance of interface can be created. 3) A class can implement multiple interfaces. 4) Many classes can implement the same interface.
There are 50 questions to complete.