Java Basic Programming Question
Java Basic Programming Question
Java Basic Programming Question
1. Program class Hello { public static void main(String args[]) { System.out.println("Hello World!"); } } 2. Program class HelloAgainAndAgain { public static void main(String[] args) { System.out.println("Hello World!"); System.out.println("Hello World!"); System.out.println("Hello World!"); System.out.println("Hello World!"); } } 3. Program class A { public static void main(String[] args) { System.out.println("Hello World!"); System.out.println(100); System.out.println(20.909); System.out.println(true); System.out.println(30 + 20); System.out.println(30 == 30); } } 4. Program class B { public static void main(String[] args) { inti = 10; System.out.println(i); } } 5. Program class B { public static void main(String[] args){ int j; System.out.println(j); } } 6. Program class C { public static void main(String[] args) { inti = 10; System.out.println(i); i = 20; System.out.println(i); i = 30; System.out.println(i); } }
201 2
7. Program class D { public static void main(String[] args) { inti; i = 10; System.out.println(i); } } 8. Program class E { public static void main(String[] args) { inti; System.out.println(i = 10); System.out.println(i); } } 9. Program class G { public static void main(String[] args) { inti, j; i = 0; j = 20; System.out.println(i + j); } } 10. Program class I { public static void main(String[] args) { int k = 1; System.out.println(k++); System.out.println(k); } } 11. Program class J { public static void main(String[] args){ inti = 1; System.out.println(++ i); System.out.println(i); } } 12. Program class K { public static void main(String[] args) { inti = 1; System.out.println(i ++); System.out.println(i); i = 2; System.out.println(i --); System.out.println(i);
www.laratechnology.com
Page 1
201 2
} public static void main(String[] args) { System.out.println("Hello World!"); test(); } } 18. Program class X { static void test(){ System.out.println("from test"); } public static void main(String[] args){ System.out.println("------"); test(); test(); test(); System.out.println("------"); } } 19. Program class B { public static void main(String[] args) { System.out.println("Hello World!"); test(10); } static void test(inti) { System.out.println(i); } } 20. Program class D { public static void main(String[] args) { inti; int j; i = 10; j = 20; System.out.println("i value:" + i + ", j value is:" + j); } } 21. Program class F { public static void main(String[] args) { inti = 20; test(i); System.out.println("done:" + i); }
www.laratechnology.com
Page 2
201 2
int j = i++ + test(i) + i; System.out.println(i); System.out.println(j); } static int test(inti) return i++; } {
} 25. Program class A { static inti; public static void main(String[] args) { System.out.println(i); } } 26. Program class B { static inti; static void test() { System.out.println("from test:" + i); } public static void main(String[] args) { System.out.println("from main:" + i); } } 27. Program class C { static inti = 10; public static void main(String[] args) { System.out.println(i); } } 28. Program class D { static void test() { System.out.println("from test:" + i); } static inti; public static void main(String[] args) { System.out.println("from main:" + i); i = 10; test(); }
www.laratechnology.com
Page 3
201 2
System.out.println(H.i); }
} 33. Program class X { static inti; public static void main(String[] args) { inti = 10; System.out.println(i); System.out.println(X.i); i = 20; X.i = 30; System.out.println(X.i); System.out.println(i); } } 34. Program class A { static inti = 10; static int j = i; public static void main(String[] args) { System.out.println(i); System.out.println(j); } } 35. Program class D { static inti = j; static int j = 10; public static void main(String[] args) { System.out.println(i); System.out.println(j); } } 36. Program class E { static inti = 10; static int j = i; static int k = m; static int m = j; public static void main(String[] args) { System.out.println(i); System.out.println(j); System.out.println(k); System.out.println(m); }
www.laratechnology.com
Page 4
201 2
System.out.println("SIB"); }
{ System.out.println("SIB1");
} public static void main(String[] args) { System.out.println("Hello World!"); } static { System.out.println("SIB2"); } } 42. Program class C { static
{ main(null);
} public static void main(String[] args) { System.out.println("Hello World!"); } } 43. Program class D { static { System.out.println(1); main(null); System.out.println(3); } public static void main(String[] args) { System.out.println("from main"); } } 44. Program class E { static inti = test(); static int test() { main(null); return 20; } public static void main(String[] args) {
www.laratechnology.com
Page 5
201 2
System.out.println(obj.i); obj.i = 10; System.out.println(obj.i);
} } 50. Program class J { int x, y = 10, z; public static void main(String[] args) { J obj1 = new J(); System.out.println(obj1.x); System.out.println(obj1.y); System.out.println(obj1.z); } } 51. Program class K { inti; public static void main(String[] args) { K k1 = new K(); k1.i = 10; K k2 = new K(); k2.i = 20; System.out.println(k1.i); System.out.println(k2.i); } } 52. Program class B { inti; double d; boolean b; public static void main(String[] args) { B b1 = new B(); System.out.println(b1.i); System.out.println(b1.d); System.out.println(b1.b); } } 53. Program class C { inti; int j = 10; C() { i = 20; } public static void main(String[] args) {
www.laratechnology.com
Page 6
201 2
System.out.println("S()"); } { System.out.println("IIB"); } public static void main(String[] args) { S s1 = new S(); System.out.println("------"); S s2 = new S(); System.out.println("------"); } } 58. Program class A { A() { System.out.println("A()"); } { System.out.println("IIB1"); } { System.out.println("IIB2"); } public static void main(String[] args) { A a1 = new A(); System.out.println("-----"); A a2 = new A(); System.out.println("-----"); } } 59. Program class C { { System.out.println("IIB1"); } public static void main(String[] args) { C c1 = new C(); System.out.println("-----"); C c2 = new C(); System.out.println("-----");
www.laratechnology.com
Page 7
201 2
B b1 = new B(); System.out.println(b1.i); System.out.println(b1.j);
} } 63. J2SE stands for? 64.JDK stands for? 65. How many classes can be in a java source file? 66.Is it possible to make empty java source file? 67.How many maximum public classes can be in one java source file? 68.Which command is used to compile java source file? 69.Which command is used to run java programs? 70.How to represent current directory in the windows Operating System? 71.By using which command we can update any environment variable for command prompt wise? 72.What is the default value to local variable? 73.What is the default value to global variable of type Boolean? 74.What is the process of passing variable to another method (by value/by reference)? 75.Is it possible to keep a method name as a class name itself? 76.Is it possible to execute something before main method execution? 77.Is it possible to keep super calling statemenet from any place of the constructor body? 78.By using which key word, we can make a sub class from the existing class? 79.How to call another constructor of the same class from the constructor body? 80. Javac command is there inside a lib folder of jdk installation(T/F)? 81. cd stands for? 82. . . represents?
} public static void main(String[] args) { F f1 = new F(); System.out.println("-----"); F f2 = new F(20); System.out.println("-----"); } } 62. Program class A { inti; } class B extends A { int j; public static void main(String[] args) {
www.laratechnology.com
Page 8
201 2
www.laratechnology.com
Page 9