if(++a == ++b*0+b){
System.out.println("A equals to B");
1.Write the Expected Output of Program }else{
public class ControlStatement { System.out.println("A is not equals to B");
public static void main(String[] args) { }
int a = 5; }
int b = 10; }
if(a>b || a<b){ Output
System.out.println("A greater than B OR A less than B");
}else{ 4. What will be the output of the following Java code?
System.out.println("Invalid Condition");
} public class LoopExample {
} public static void main(String[] args) {
} int i = 55;
for(; i<70; i++){
Output System.out.print(" "+i);
i++;
}
2.Write the Expected code of following program }
}
class brak1
{ output
public static void main(String args[])
{
5.write the output of the following Program
for(int k=1;k<=10;k++)
{ public class LoopExample {
if(k!=5) public static void main(String[] args) {
continue; for( ; ; ){
System.out.println(k); System.out.print("Hello Loop");
} }
} }
} }
output
output
3. What will be the output of the following Java code?
public class ControlStatement {
public static void main(String[] args) {
int a = 5;
int b = 5;
9. write the output of the following Program
6. write the output of the following Program public class Main {
import java.util.StringTokenizer; public static void main(String[] args) {
public class Simple{ String myStr = "Hello";
public static void main(String args[]){ char result = myStr.charAt(6);
StringTokenizer st = new StringTokenizer("b i t s"," "); System.out.println(result);
while (st.hasMoreTokens()) { }
System.out.println(st.nextToken()); }
} Output:
}
}
output: 10. write the output of the following Program
public class Main {
public static void main(String[] args) {
String myStr = "Hello";
7. write the output of the following Program
System.out.println(myStr.endsWith("Hel"));
import java.util.StringTokenizer; System.out.println(myStr.endsWith("llo"));
public class StringTokenizer3 System.out.println(myStr.endsWith("o"));
{ }
public static void main(String args[]) } Output:
{
StringTokenizer st = new StringTokenizer("Hello Everyone Have a nice
day"," "); 11. How to declare PI = 3.14 as a constant ________________________.
System.out.println("Total number of Tokens: "+st.countTokens());
} 12. __________________keyword must be used to inherit a class.
}
13. __________________keyword used to define an abstract class.
Output:
14. What is the purpose of the 'super' keyword in Java? [ ]
8. write the output of the following Program A. To call the constructor of the parent class
B. To call a method of the child class
import java.util.Arrays; C. To create a new instance of a class
public class Main { D. To define a static method
public static void main(String[] args) {
String[] cars = {"Volvo", "BMW", "Tesla", "Ford", "Fiat", "Audi"}; 15. What is a multilevel inheritance in Java? [ ]
Arrays.sort(cars); A. A class extends two or more classes
for (String i : cars) { B. Two or more classes extend the same class
System.out.println(i); C. A class extends another class which also extends another class
} D. All of the above
}
}
Output:
public Mid1() { ctr++; }
public static void main(String[] args)
16.Find the output of the Program {
public class Vehicle { Mid1 obj1 = new Mid1 ();
public void move() { Mid1obj2 = new Mid1 ();
System.out.println("The vehicle moves"); Mid1 obj3 = new Mid1 ();
} System.out.println("Number of objects created are "
} + Mid1.ctr);
public class Car extends Vehicle { }
public void move() { } Output:
System.out.println("The car moves");
} 19.. Fill the Code
} import java.util.*;
public class Main { class Main {
public static void main(String[] args) { public static void main(String[] args)
Vehicle vehicle = new Car(); {
vehicle.move(); // Scanner class with System.in
} Scanner sc = new Scanner(System.in);
} Output: // Taking input from the user
17..Find the output of the Program
class First
{
static void staticMethod()
{
System.out.println("Static Method");
} // Printing the output
} System.out.printf("Addition: %d", x + y);
public class MainClass }
{ }
public static void main(String[] args) 5. Find the output of the Program
{ class op
First first = null; {
first.staticMethod(); public static void main(String args[])
} {
} int a=1;
int b=2;
Output a+=5;
b*=4;
System.out.println("a="+a);
System.out.println("b="+b);
}
18. .Find out How many objects are created } Output
class Mid1 {
public static int ctr = 0;
23. Find the Output of the Program
20. Find the Output of the Program String str = "abc"; str.concat("xyz");
class String_demo1 System.out.println(str);
{ output:
public static void main(String args[])
{ 24. Find the Output of the Program
char chars[] = {'a', 'b', 'c'}; String s = "Welcome";
String s = new String(chars); s.replace('W', 'w');
System.out.println(s); System.out.println(s);
} output:
} Output
25. What does s.equalsIgnoreCase("hello") [ ]
return if s = "Hello"?
21. Find the Output of the Program
a) true b) false c) Compilation Error d) Runtime Error
class Output
{ 26. Find the Output of the Program
public static void main(String args[]) StringBuffer sb = new StringBuffer("Hello");
{ sb. append (" World"); System.out.println(sb);
double x = 2.0;
double y = 3.0;
double z = Math.pow( x, y ); output:
System.out.print(z); 27. Which class allows modification of string content? [ ]
}
} a) String b) StringBuffer c) StringTokenizer d) None of the above
Output
28. Find the Output of the Program
22. Find the Output of the Program StringBuffer sb = new StringBuffer("Hello");
sb.append(" World");
class Output System.out.println(sb);
{ output:
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5}; 29. What will s.length() return for the string [ ]
for ( int i = 0; i < arr.length - 3; ++i) String s = "Hello World";?
System.out.println(arr[i] + " ");
} a) 10 b) 11 c) 12 d) 13
} Output:
{
for (int j = 1; j <= i; j++) {
-*-
System.out.print(j + " ");
30. What will be the output of the following Java code? }
System.out.println();
class array_output
{ }
public static void main(String args[]) } output:
{ }
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i) 33. Write the output for the following Code
{ class Grandparent {
array_variable[i] = i; public void print() {
System.out.print(array_variable[i] + " "); System.out.println("Grandparent's Print()");
i++; }
} }
} class Parent extends Grandparent { } output:
} class Child extends Parent { }
output: public class Main {
31. Write the output for the following Code public static void main(String[] args) {
class pattern Child child = new Child();
{ child.print();
public static void main(String args[]) }
{ output: }
for(int i=0;i<5;i++) 34. Write the output for the following Code
{ class Base
{
for(int j=i;j<5;j++)
void showme()
{ {
System.out.print("*"); System.out.println(" Base class method"); output:
} }
System.out.println(); }
} class Child extends Base
} {
} void showme()
32. Write the output for the following Code {
class pattern System.out.println("Child class method");
{ }
public static void main(String args[]) public static void main(String... a)
{ {
for (int i = 5; i >= 1; i--) Child obj = new Child();
obj.showme();
}
}
int arr[] = {1, 2, 3, 4, 5};
35. Write the output for the following Code for ( int i = 0; i < arr.length - 5; System.out.println(arr[i++]);
}
String s = "Java Programming"; }
System.out.println(s.substring(5, 9)); 41. What does this code output?
output:
String[] nums = new String[] { "1", "9", "10" }; output:
Arrays.sort(nums);
System.out.println(Arrays.toString(nums));
36. Write the output for the following Code
42. What does this code output?
StringTokenizer st = new StringTokenizer("A-B-C", "-"); public class Test{
while (st.hasMoreTokens()) public static void main(String []args){
{ output: int i = 0; output:
System.out.println(st.nextToken()); for(i = 0; i < 10; i++){
} break;
}
System.out.println(i);
37. Which method is used to get the remaining tokens from }
StringTokenizer? [ ] }
a) nextToken() b) hasMoreTokens() 43. What does this code output?
c) countTokens() d) getNext() public class Test{
public static void main(String []args){
38. Write the output for the following Code int i = 0;
for(i = 0; i < 10; i++){ output:
StringBuffer sb = new StringBuffer("ABC"); break;
sb.setCharAt(2, 'Z'); }
output: System.out.println(i);
System.out.println(sb); }
}
44. What does this code output?
public class Test{
39. Which of these is an incorrect array declaration? [ ]
public static void main(String []args){
a) int arr[] = new int[5] for(int i = 0; i < 10; i++){
b) int [] arr = new int[5] if(i % 2 == 0){
c) int arr[] = new int[5] continue;
d) int arr[] = int [5] new }
System.out.println(i); output:
40. Find the Output of the Program }
}
class Output output: }
{
public static void main(String args[]) Write if any error. Otherwise, Write output.
{
obj.length = 10;
45. Write the Expected Output of Program int y = obj.width * obj.height * obj.length;
System.out.print(y);
class Test12 }
{ }
public static void main (String args[]) output
{
int month_days[]={31,28,31,30,31,30,31,30,31,30,31};
System.out.println("April has " +month_days[3]+ " days");
}
}
Output
48.write the output of the following Program
class Output6
{
46. What will be the output of the following Java code? public static void main(String args[])
class increment { {
public static void main(String args[]) int arr[] = {1, 2, 3, 4, 5};
{ for ( int i = 0; i < arr.length - 2; ++i)
int g = 3; System.out.println(arr[i] + " ");
System.out.print(++g * 8); }
} }
}
Output
49.Find the output of the Program
class String_demo1
47. What will be the output of the following Java code? {
public static void main(String args[])
class box {
{ char chars[] = {'a', 'b', 'c'};
int width; String s = new String(chars);
int height; System.out.println(s);
int length; Output
}
class main5
{
public static void main(String args[])
{
box obj = new box();
obj.width = 10;
obj.height = 2;
}
50. }
Find } Output
the
output of the Program
class op
{ 53. What is the correct output of this program ?
public static void main(String args[]) public class ControlStatement {
{ public static void main(String[] args) {
int a=1; int a = 5;
int b=2; int b = 5;
a+=5; if(a++ == b){
b*=4; System.out.println("A equals to B");
System.out.println("a="+a); }
System.out.println("b="+b);
else{
}
System.out.println("A is not equals to B");
}
Output }
}
Output
}
54. What is the correct
51. What is the right output of this program? output of this program ?
public class ShiftOperators { public class ControlStatement {
public static void main(String[] args) public static void main(String[] args) {
{ int a = 5;
System.out.print(8<<2); int b = 5;
System.out.print(","); if(a++ < ++b){
System.out.print(8>>1); System.out.println("A less than B");
} Output }else{
} System.out.println("A greater than B");
}
} Output
}
52. What is the correct output of this program ?
public class ControlStatement {
55. What is the correct output of this program ?
public static void main(String[] args) {
public class LoopExample {
int a = 5;
public static void main(String[] args) {
int b = 10;
int i = 55;
if(a>b || a<b){
for(; i<70; i++){
System.out.println("A greater than B OR A less than B");
System.out.print(" "+i);
}
i++;
else {
}
System.out.println("Invalid Condition");
} {
} int array_variable [] = new int[10];
Output for (int i = 0; i < 10; ++i)
{
array_variable[i] = i;
System.out.print(array_variable[i] + " ");
56. What is the correct output of this program ? i++;
public class LoopExample { } Output
public static void main(String[] args) { }
int i = 70; }
for(; i>60; ){
System.out.print(" "+i); 60. What is the correct output of this program ?
i--; class evaluate
} {
} Output public static void main(String args[])
} {
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
57. What is the correct output of this program? n = arr[arr[n] / 2];
public class LoopExample { System.out.println(arr[n] / 2);
public static void main(String[] args) { }
for( ; ; ){ } Output
System.out.print("Hello Loop");
}
} 61. What is the correct output of this program ?
} class array_output
Output {
public static void main(String args[])
58. What is the correct output of this program ? {
public class LoopExample { char array_variable [] = new char[10];
public static void main(String[] args) { for (int i = 0; i < 10; ++i)
for(int i=0; i<10; i++ ); {
System.out.print("Hello Loop"); array_variable[i] = 'i';
} System.out.print(array_variable[i] + "");
} }
Output }
}
59. What
Output
is the correct output of this program ?
class array_output 62. What will be the output of the following Java program?
{ class selection_statements
public static void main(String args[]) {
public static void main(String args[]) class Output
{ {
int var1 = 5; public static void main(String args[])
int var2 = 6; {
if ((var2 = 1) == var1) boolean a = true;
System.out.print(var2); boolean b = false;
else boolean c = a ^ b;
System.out.print(++var2); System.out.println(!c);
} }
} }
Output Output
63. What will be the output of the following Java code? 66. What
class bool_operator will be the output of the following Java program?
{ class bitwise_operator
public static void main(String args[]) {
{ public static void main(String args[])
boolean a = true; {
boolean b = !true; int a = 3;
boolean c = a | b; int b = 6;
boolean d = a & b; int c = a | b;
boolean e = d ? b : c; int d = a & b;
System.out.println(d + " " + e); System.out.println(c + " " + d);
} }
} }
Output Output
64. What will be the output of the following Java code? 67. What
class Output will be the output of the following Java program?
{ class Output
public static void main(String args[]) {
{ public static void main(String args[])
int x , y = 1; {
x = 10; int a = 1;
if (x != 10 && x / 0 == 0) int b = 2;
System.out.println(y); int c = 3;
else a |= 4;
System.out.println(++y); b >>= 1;
} c <<= 1;
} a ^= c;
Output System.out.println(a + " " + b + " " + c);
65. What will be the output of the following Java code?
} int d;
} c = ++b;
Output d = a++;
c++;
68. What will be the output of the following Java code? b++;
class output ++a;
{ System.out.println(a + " " + b + " " + c);
public static void main(String args[]) }
{ }
String s1 = "Hello i love java"; Output
String s2 = new String(s1);
System.out.println((s1 == s2) + " " + s1.equals(s2));
}
}
Output
69. What *-*-*
will be the output of the following Java program?
class increment
{
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
Output
70. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int a = 1;
int b = 2;
int c;