Java Questions
Java Questions
....
String s = "abc";
StringBuffer sb = new StringBuffer("abc");
changeObjects (s, sb);
System.out.println(s);
System.out.println(sb);
char v1 = '(';
int i = ~v1;
System.out.println(i);
5) Class Pass {
public static int x, y;
public void test(int x, int z) {
x += x << 3;
y += z << 2;
}
public static void main(String[] args) {
Pass pass = new Pass();
x = 6;
y = 5;
pass.test(x, y);
System.out.println(x + y);
}
}
6)
String test = new String("hello");
String test1 = new String("hello");
7)
public class Test
{
private int i = giveMeJ();
private int j;
8)
public class Test
{
public static void main(String args[])
{
StringBuffer str1="Hello";
StringBuffer str2=" there";
StringBuffer str3=str1+str2;
System.out.println(str3);
}
}
9)
boolean b = false;
if(b = false) {
System.out.println("b is false");
} else if(b = true){
System.out.println("b is true");
} else {
System.out.println("b is not true or false");
}
10)
public class Test
{
public static void main(String args[])
{
int j=0;
for (int i = 0; i < 2; ) {
System.out.println(i);
i = i++;
System.out.println(i);
j++;
if(j==100)
break;
}
}
}
11)
class JMM101 {
public static void main(String[] args) {
int i = 0;
while (i++ < args.length) {
System.out.print(args[i]);
}}}
12)
abstract class test
{
abstract public void checkThis() throws SecurityException;
public void checkThat(){};
}
public class Test extends test
{
public void checkThis() throws SecurityException
{
}
}
13)
abstract class test
{
abstract public void checkThis() throws SecurityException;
}
class Test1 extends test
{
public void checkThis() throws SecurityException
{
}
}
public class Test extends Test1
{
public void checkThis(int x) throws SecurityException,ClassCastException
{
}
}
14)
class EBH023 {
static String m1(boolean b){return b?"T":"F";}
public static void main(String [] args) {
boolean b1 = false?false:true?false:true?false:true;
boolean b2 = false?false : ( true?false : ( true?false:true));
boolean b3 = ((false?false:true)?false:true)?false:true;
System.out.println(m1(b1) + m1(b2) + m1(b3));
}}
15)
class A
{
B b;
A()
{
b=new B();
System.out.println(b.toString());
}
public String toString()
{
return "I am A ";
}
}
class B
{
A a;
B()
{
a=new A();
System.out.println(a.toString());
}
public String toString()
{
return "I am B ";
}
}
public class Test
{
public static void main(String[] ar)
{
A a=new A();
B b=new B();
}
}
16)
int i=0, j = ++i + ++i * ++i;
System.out.print(j);
17)
class Fish
{
public void bite(int howHard)
{
System.out.println("Fish::bite");
}
}
s.bite(10);
f.bite(10);
}
}
18)
public class Test {
public static void main (String [] args) {
short[][] b = new short[4][4];
short[][] big = new short[2][2];
short b3 = 8;
short b2[][][] = new short[2][3][2][2];
//insert code here
}
}
19)
class A11 {
return "A11";
}}
class A12 {
public static void main(String[] arg) {
System.out.print(a3[2][1][0]); // 7
}}
20)
class B{
{
System.out.println("5");
}
static {
System.out.println("4");
}
{
System.out.println("6");
}
}
class A extends B{
{
System.out.println("2");
}
static{
System.out.println("1");
}
A(){
System.out.println("3");
}
21)
public class Test
{
int a;
public Test()
{
a = 100;
}
public void show()
{
System.out.println(this);
System.out.println("the value of a is "+a);
}
}
}
22)
class t1
{
public static void main (String st[])
{
m1(1);
}
23)
class t{
public static void main(String []a){
new t().gn();
}
}
}
24)
class ValHold1{
public int i = 10;
}
}//End of amethod
25)
int i = -1;
byte b = 2;
short s = 3;
short s2 = 10;
char c = 'd' - 'b';
long l = 5;
float f = 1.0f;
double d = 1;
26)
System.out.print(arg);
}
}
27)
class ClassA {
public static void main(String[] args) {
int i = 1999;
i = 1 + (new Object() {
public int getI() {
return i;
}
}).getI();
System.out.println("i = "+i);
}
}
28)
29)
30)
class EBH202 {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
31)
public class Test2 extends Base
{
Test2(long i)
{
super(2);
}
Test2()
{
super(2);//2
}
class Base
{
Base(int i)
{
System.out.println(i);
}
}
32)
class LoopTest100{
static int i,j;
public static void main(String[] args) {
for (i = 0;i <3;i++,System.out.print(i)) { }
System.out.println();
for (j = 0;j<3;++j) {
System.out.print(j);
}
}
}
33)
class StringTest1 {
public static void main(String[] args) {
String s1 = " Arg ";
s1= s1.trim();
System.out.println(s1+ args[1] );
System.out.println();
34)