Sie sind auf Seite 1von 12

1. What is the output of following Code?

class Test
{
static
{
int a = 20 ;
System.out.println(Test.a);
Test.a = Test.a + a ;
}
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

2. What is the output of following Code?


class Test
{
int a ;
Test(int a)
{
a = this.a ;
this.a = a ;
}
public static void main(String[] args)
{
Test obj = new Test(10);
System.out.println(obj.a);
}
}

3. What is the output of following Code?


class Variables
{
public static void main(String[] args)
{
int a ;
System.out.println(a);
}
}

4. What is the output of following Code?


class Test
{
int a ;
Test(int x)
{
a = x + 20;
x = this.a + 10;
System.out.println(x);
}
public static void main(String[] args)
{
Test obj = new Test(10);
System.out.println(obj.a);
}
}
5. What is the output of following Code?
class Variables
{
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Variables.a);
System.out.println(a);
}
}

6. What is the output of following Code?


class Test
{
static int a = 50 ;
public static void main(String[] args)
{
System.out.println(Test.fun()+Test.a);
}
static int fun()
{
return Test.a+100;
}
}

7. What is the output of following Code?


class Test
{
static
{
int a = 20 ;
Test.a = Test.a + a ;
a = a + Test.a ;
Test.a = a + a ;
}
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

8. What is the output of following Code?


class Variables
{
static
{
int a=10 ;

public static void main(String[] args)


{
System.out.println(Variables.a);

9. What is the output of following Code?


class Test
{
static int a ;
public static void main(String[] args)
{
Test.a = Test.m1(10);
System.out.println(Test.a);
}
static int m1(int a)
{
return Test.m2(20) + a ;
}
static int m2(int a)
{
return Test.a + Test.m3(20) ;
}
static int m3(int a)
{
return Test.a + a ;
}
}

10. What is the output of following Code?


class Variables
{
static
{
System.out.println(Variables.a);
}
public static void main(String[] args)
{
System.out.println(Variables.a);
}
static int a = 10 ;
}

11. what is the output of following code?


class Test
{
static int a = 100 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

12.what is the output of following code?

class Test
{
static int a = 100 ;
public static void main(String[] args)
{
int a = 200;
System.out.println(Test.a);
System.out.println(a);
}
}

13.what is the output of following code?

class Test
{
static
{
System.out.println("Static block....");
}
public static void main(String arg[ ])
{
System.out.println("Main method....");
}
}

14.what is the output of following code?

class Test
{
public static void main(String arg[ ])
{
System.out.println("Main method....");
}
static
{
System.out.println("Static block....");
}
}

15.what is the output f following code?

class Test
{
static
{
System.out.println("Static block1");
}
public static void main(String arg[ ])
{
System.out.println("Main method....");
}
static
{
System.out.println("Static block2");
}
}

16.what is the output of following code?

class Test
{
static int a = 100 ;
static
{
System.out.println("Static block");
System.out.println(Test.a);
}
public static void main(String[] args)
{
System.out.println("Main method");
System.out.println(Test.a);
}
}
17.what is the output of following code?

class Test
{
static int a ;
static
{
System.out.println(Test.a);
}
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

18.what id the output of following code?

class Test
{
static int a ;
static char b ;
static float c ;
static boolean d ;
static String e ;
public static void main(String[] args)
{
System.out.println("/***Data types & Default Values***/");
System.out.println("int : "+Test.a);
System.out.println("char : "+Test.b);
System.out.println("float : "+Test.c);
System.out.println("boolean : "+Test.d);
System.out.println("Pointer : "+Test.e);
}
}

19.what is the output of following code?

class Test
{
public static void main(String[] args)
{
int a = 100 ;
System.out.println(a);
}
}
20.what is the output of following code?

class Test
{
public static void main(String[] args)
{
int a = 100 ;
System.out.println(a);
}
}

21.what is the output of following code?


class Test
{
static int a = 100 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

22.what is the output of following code?

class Test
{
static int a = 100 ;
public static void main(String[] args)
{
System.out.println(Test.a);
System.out.println(a);
}
}

23.what is the output of following code?

class Test
{
static int a = 100 ;
public static void main(String[] args)
{
int a = 200;
System.out.println(Test.a);
System.out.println(a);
}
}
24.what is the output of following code?

class Test
{
static
{
System.out.println("Static block");
}
public static void main(String[] args)
{
System.out.println("Main method");
}
}

25.what is the output of following code?

class Test
{
static int a ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

26.what is the output of following code?


class Test
{
static int a = 100 ;
static
{
System.out.println("Static block");
System.out.println(Test.a);
}
public static void main(String[] args)
{
System.out.println("Main method");
System.out.println(Test.a);
}
}

27.what is the output of the following code?

class Test
{
public static void main(String[] args)
{
System.out.println("Main method");
}

static void fun( )


{
System.out.println("User method....");
}
}

28.what is the output of the following code?

class Test
{
public static void main(String[] args)
{
System.out.println("Main method starts....");
Test.fun( );
System.out.println("Main method ends....");
}

static void fun( )


{
System.out.println("User method....");
}
}

29.what is the output of the following code?

class Test
{
public static void main(String[] args)
{
System.out.println("main starts");
Test.fun();
System.out.println("ctrl back to main method....");
}
static void fun( )
{
System.out.println("ctrl in fun");
}

static
{
System.out.println("block starts");
Test.fun();
System.out.println("ctrl back to block from fun...");
}
}

30.what is the output of the following code?

class Test
{
static int a = 10 ;
public static void main(String[] args)
{
int a = 20;
Test.a = Test.a + a ;
a = a + Test.a ;
Test.a = Test.a + a + Test.a ;
System.out.println(Test.a);
System.out.println(a);
}
}

31.what is the output of the following code?

class Test
{
static
{
int a = 20 ;
System.out.println("Global a : "+Test.a);
Test.a = Test.a + a ;
}
static int a = 10 ;
public static void main(String[] args)
{
System.out.println("Global a : "+Test.a);
}
}

32.what is the output of the following code?

class Test
{
static
{
int a = 20 ;
Test.a = Test.a + a ;
a = a + Test.a ;
Test.a = a + a ;
}
static int a ;
public static void main(String[] args)
{
System.out.println("Global a : "+Test.a);
}
}

33.what is the output of the following code?

class Pro1
{
static int a = 50 ;
public static void main(String[] args)
{
System.out.println(Pro1.fun()+Pro1.a);
}
static int fun()
{
Pro1.a = Pro1.a +100;
return Pro1.a;
}
}

34.what is the output of the following code?

class Pro1
{
static
{
Pro1.a = Pro1.fun();
}
static int a = 70 ;
public static void main(String[] args)
{
System.out.println(Pro1.a);
}
static
{
Pro1.a = Pro1.a+Pro1.fun();
}
static int fun()
{
Pro1.a = 50;
return Pro1.fun1();
}
static int fun1()
{
System.out.println(Pro1.a);
return Pro1.a+30;
}
}

35.what is the output of the following code?

class Login
{
static
{
System.out.println("Login page is loading....");
}
public static void main(String[] args)
{
System.out.println("Communication starts....");
Inbox.mailInfo();
}
}

class Inbox
{
static
{
System.out.println("Inbox page is loading....");
}
static void mailInfo()
{
System.out.println("Recent mail info.....");
}
}

36.what is the output of following code?

class Test
{
final static int x;
public static void main(String[] args)
{
}
}

37.what is the output of following code?

class Test
{
final static int x = 10;
public static void main(String[] args)
{
System.out.println(x);
}
}

38.what is the output of following code?

class Test
{
final static int x;
static
{
x = 10;
}
public static void main(String[] args)
{
System.out.println(x);
}
}

39.what is the output of following code?

class Test
{
final static int x;
public static void m()
{
x = 10;
}
public static void main(String[] args)
{
System.out.println(x);
}
}

40.what is the output of following code?

class MainClass
{
final static String company = "CTS";
String name;
int rollno;
public static void main(String[] args)
{
MainClass ob = new MainClass();
ob.company = "CTS";
ob.name = "Naresh";
ob.rollno = 007;
System.out.println(ob.company);
System.out.println(ob.name);
System.out.println(ob.rollno);
}
}

41.what is the output of following code?

public class StaticMethodTest


{
public static void main(String[] args) {
staticMethod();
}

static void staticMethod() {


System.out.println("in staticMethod()");
}

42.what is the output of following code?

public class Outer {


static class Nested_Demo {
public void my_method() {
System.out.println("This is my nested class");
}
}
public static void main(String args[]) {
Outer.Nested_Demo nested = new Outer.Nested_Demo();
nested.my_method();
}
}

43.what is the output of following code?


class Example
{
static int a;
static void m1(int x){
a=x;
System.out.println(a);
}
public static void main(String[] args)
{
System.out.println(a);
m1(50);
System.out.println(a);
}
}

44. what is the output of following code?

class A
{
static void staticMethod()
{
System.out.println("Static Method");
}
}

public class MainClass


{
public static void main(String[] args)
{
A a = null;

a.staticMethod();
}
}

45.what is the output of following code?

class Calculation
{
static int sqr(int p){
return p*p;
}

public static void main(String args[]){


int result=Calculation.sqr(5);
System.out.println(result);
}
}

Das könnte Ihnen auch gefallen