0% found this document useful (0 votes)
4 views33 pages

500 Java Code Output Questions With Point Names

The document contains 500 Java code output questions divided into sections covering variable declaration, initialization, scope, identifier rules, variable assignment, final variables, and data types. Each section includes multiple questions with corresponding Java code snippets and expected outputs. The questions range from basic concepts to more advanced topics, providing a comprehensive overview of Java programming.

Uploaded by

omkarregade78
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views33 pages

500 Java Code Output Questions With Point Names

The document contains 500 Java code output questions divided into sections covering variable declaration, initialization, scope, identifier rules, variable assignment, final variables, and data types. Each section includes multiple questions with corresponding Java code snippets and expected outputs. The questions range from basic concepts to more advanced topics, providing a comprehensive overview of Java programming.

Uploaded by

omkarregade78
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

500 Java Code Output Questions with Point Names

Section 1: Variable Declaration & Initialization (Questions 1-50)

Point 1.1: Basic Variable Declaration (Questions 1-10)


Q1: Simple Integer Declaration

java

public class Test {


public static void main(String[] args) {
int x = 10;
[Link](x);
}
}

Q2: Multiple Variable Declaration

java

public class Test {


public static void main(String[] args) {
int a = 5, b = 10, c = 15;
[Link](a + b + c);
}
}

Q3: Uninitialized Local Variable

java

public class Test {


public static void main(String[] args) {
int x;
[Link](x);
}
}

Q4: Final Variable Reassignment

java
public class Test {
public static void main(String[] args) {
final int x = 10;
x = 20;
[Link](x);
}
}

Q5: Variable Redeclaration

java

public class Test {


public static void main(String[] args) {
int x = 10;
int x = 20;
[Link](x);
}
}

Q6: Default Static Variable Value

java

public class Test {


static int count;
public static void main(String[] args) {
[Link](count);
}
}

Q7: Default Instance Variable Value

java

public class Test {


int value;
public static void main(String[] args) {
Test t = new Test();
[Link]([Link]);
}
}

Q8: String Default Value


java

public class Test {


String name;
public static void main(String[] args) {
Test t = new Test();
[Link]([Link]);
}
}

Q9: Boolean Default Value

java

public class Test {


boolean flag;
public static void main(String[] args) {
Test t = new Test();
[Link]([Link]);
}
}

Q10: Array Default Values

java

public class Test {


public static void main(String[] args) {
int[] arr = new int[3];
[Link](arr[0] + " " + arr[1] + " " + arr[2]);
}
}

Point 1.2: Variable Scope (Questions 11-20)


Q11: Block Scope

java
public class Test {
public static void main(String[] args) {
int x = 10;
{
int x = 20;
[Link](x);
}
[Link](x);
}
}

Q12: If Block Scope

java

public class Test {


public static void main(String[] args) {
if (true) {
int y = 20;
}
[Link](y);
}
}

Q13: For Loop Scope

java

public class Test {


public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
[Link](i + " ");
}
[Link](i);
}
}

Q14: Static vs Instance Variable

java
public class Test {
static int x = 100;
public static void main(String[] args) {
int x = 200;
[Link](x);
}
}

Q15: Method Parameter Scope

java

public class Test {


static int x = 10;
public static void main(String[] args) {
method(20);
[Link](x);
}
static void method(int x) {
[Link](x);
}
}

Q16: Nested Block Scope

java

public class Test {


public static void main(String[] args) {
int x = 1;
{
int y = 2;
{
int z = 3;
[Link](x + y + z);
}
[Link](x + y);
}
[Link](x);
}
}

Q17: Variable Shadowing

java
public class Test {
int value = 100;
public static void main(String[] args) {
Test t = new Test();
[Link]();
}
void display() {
int value = 200;
[Link](value);
[Link]([Link]);
}
}

Q18: Switch Case Scope

java

public class Test {


public static void main(String[] args) {
int x = 1;
switch (x) {
case 1:
int y = 10;
break;
case 2:
int y = 20;
break;
}
}
}

Q19: Try-Catch Scope

java

public class Test {


public static void main(String[] args) {
try {
int x = 10;
} catch (Exception e) {
int x = 20;
}
[Link](x);
}
}
Q20: Variable Access Across Blocks

java

public class Test {


public static void main(String[] args) {
int x;
if (true) {
x = 10;
}
[Link](x);
}
}

Point 1.3: Identifier Rules (Questions 21-30)


Q21: Valid Identifier with Underscore

java

public class Test {


public static void main(String[] args) {
int _value = 100;
[Link](_value);
}
}

Q22: Valid Identifier with Dollar

java

public class Test {


public static void main(String[] args) {
int $price = 200;
[Link]($price);
}
}

Q23: Invalid Identifier Starting with Number

java
public class Test {
public static void main(String[] args) {
int 2value = 10;
[Link](2value);
}
}

Q24: Reserved Keyword as Identifier

java

public class Test {


public static void main(String[] args) {
int class = 50;
[Link](class);
}
}

Q25: Case Sensitivity

java

public class Test {


public static void main(String[] args) {
int Value = 10;
int value = 20;
[Link](Value + value);
}
}

Q26: Unicode Identifier

java

public class Test {


public static void main(String[] args) {
int π = 314;
[Link](π);
}
}

Q27: Similar to Keyword but Valid

java
public class Test {
public static void main(String[] args) {
int classes = 5;
int forloop = 10;
[Link](classes + forloop);
}
}

Q28: Single Character Identifier

java

public class Test {


public static void main(String[] args) {
int a = 1, b = 2, c = 3;
[Link](a + b + c);
}
}

Q29: Long Identifier Name

java

public class Test {


public static void main(String[] args) {
int thisIsAVeryLongVariableName = 100;
[Link](thisIsAVeryLongVariableName);
}
}

Q30: Mixed Characters in Identifier

java

public class Test {


public static void main(String[] args) {
int value123_$ = 500;
[Link](value123_$);
}
}

Point 1.4: Variable Assignment and Reassignment (Questions 31-40)


Q31: Basic Assignment

java
public class Test {
public static void main(String[] args) {
int x = 5;
int y = x;
x = 10;
[Link](x + " " + y);
}
}

Q32: Chain Assignment

java

public class Test {


public static void main(String[] args) {
int a, b, c;
a = b = c = 10;
[Link](a + " " + b + " " + c);
}
}

Q33: Self Assignment

java

public class Test {


public static void main(String[] args) {
int x = 5;
x = x + 10;
[Link](x);
}
}

Q34: Assignment in Expression

java

public class Test {


public static void main(String[] args) {
int x = 5;
int y = (x = 10) + 5;
[Link](x + " " + y);
}
}
Q35: Assignment Return Value

java

public class Test {


public static void main(String[] args) {
int x, y;
[Link](x = y = 20);
}
}

Q36: Multiple Assignments

java

public class Test {


public static void main(String[] args) {
int x = 1;
x = x + 1;
x = x * 2;
x = x - 3;
[Link](x);
}
}

Q37: Assignment with Different Types

java

public class Test {


public static void main(String[] args) {
int x = 10;
double y = x;
[Link](x + " " + y);
}
}

Q38: Assignment in Loop

java
public class Test {
public static void main(String[] args) {
int x = 0;
for (int i = 0; i < 3; i++) {
x = i + 1;
}
[Link](x);
}
}

Q39: Assignment with Method Call

java

public class Test {


public static void main(String[] args) {
int x = getValue();
[Link](x);
}
static int getValue() {
return 42;
}
}

Q40: Assignment with Array

java

public class Test {


public static void main(String[] args) {
int[] arr = {10, 20, 30};
int x = arr[1];
arr[1] = 25;
[Link](x + " " + arr[1]);
}
}

Point 1.5: Final Variables (Questions 41-50)


Q41: Final Variable Basic

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

Q42: Final Variable Modification

java

public class Test {


public static void main(String[] args) {
final int x = 10;
x++;
[Link](x);
}
}

Q43: Final Variable Late Initialization

java

public class Test {


public static void main(String[] args) {
final int x;
x = 20;
[Link](x);
}
}

Q44: Final Variable Multiple Assignment

java

public class Test {


public static void main(String[] args) {
final int x;
x = 10;
x = 20;
[Link](x);
}
}

Q45: Final Array Reference


java

public class Test {


public static void main(String[] args) {
final int[] arr = {1, 2, 3};
arr[0] = 10;
[Link](arr[0]);
}
}

Q46: Final Array Reassignment

java

public class Test {


public static void main(String[] args) {
final int[] arr = {1, 2, 3};
arr = new int[]{4, 5, 6};
[Link](arr[0]);
}
}

Q47: Final Static Variable

java

public class Test {


static final int VALUE = 100;
public static void main(String[] args) {
[Link](VALUE);
}
}

Q48: Final Instance Variable

java

public class Test {


final int value = 50;
public static void main(String[] args) {
Test t = new Test();
[Link]([Link]);
}
}

Q49: Final Parameter


java

public class Test {


public static void main(String[] args) {
method(25);
}
static void method(final int x) {
x = 30;
[Link](x);
}
}

Q50: Final in Loop

java

public class Test {


public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
final int x = i;
[Link](x + " ");
}
}
}

Section 2: Data Types (Questions 51-150)

Point 2.1: Primitive Data Types - Integer Types (Questions 51-70)


Q51: Byte Range

java

public class Test {


public static void main(String[] args) {
byte b = 127;
b++;
[Link](b);
}
}

Q52: Byte Overflow

java
public class Test {
public static void main(String[] args) {
byte b = 100;
b = (byte)(b + 50);
[Link](b);
}
}

Q53: Short Operations

java

public class Test {


public static void main(String[] args) {
short s1 = 10;
short s2 = 20;
short s3 = (short)(s1 + s2);
[Link](s3);
}
}

Q54: Integer Literals

java

public class Test {


public static void main(String[] args) {
int octal = 017;
int hex = 0x1F;
int binary = 0b11111;
[Link](octal + " " + hex + " " + binary);
}
}

Q55: Long Suffix

java

public class Test {


public static void main(String[] args) {
long l1 = 2147483648;
long l2 = 2147483648L;
[Link](l1 + " " + l2);
}
}
Q56: Integer Division

java

public class Test {


public static void main(String[] args) {
int a = 7;
int b = 2;
[Link](a / b);
}
}

Q57: Integer Modulo

java

public class Test {


public static void main(String[] args) {
int a = 17;
int b = 5;
[Link](a % b);
}
}

Q58: Negative Modulo

java

public class Test {


public static void main(String[] args) {
int a = -17;
int b = 5;
[Link](a % b);
}
}

Q59: Integer Max Value

java
public class Test {
public static void main(String[] args) {
int max = Integer.MAX_VALUE;
[Link](max);
[Link](max + 1);
}
}

Q60: Integer Min Value

java

public class Test {


public static void main(String[] args) {
int min = Integer.MIN_VALUE;
[Link](min);
[Link](min - 1);
}
}

Q61: Byte Addition

java

public class Test {


public static void main(String[] args) {
byte a = 50;
byte b = 60;
byte c = a + b;
[Link](c);
}
}

Q62: Short Multiplication

java

public class Test {


public static void main(String[] args) {
short a = 200;
short b = 200;
short c = (short)(a * b);
[Link](c);
}
}
Q63: Long Arithmetic

java

public class Test {


public static void main(String[] args) {
long a = 5000000000L;
long b = 2;
[Link](a * b);
}
}

Q64: Mixed Integer Types

java

public class Test {


public static void main(String[] args) {
byte b = 10;
short s = 20;
int i = 30;
long l = 40L;
[Link](b + s + i + l);
}
}

Q65: Integer Type Promotion

java

public class Test {


public static void main(String[] args) {
byte a = 40;
byte b = 50;
int result = a * b;
[Link](result);
}
}

Q66: Underscore in Literals

java
public class Test {
public static void main(String[] args) {
int million = 1_000_000;
[Link](million);
}
}

Q67: Hexadecimal Operations

java

public class Test {


public static void main(String[] args) {
int a = 0xFF;
int b = 0x10;
[Link](a + b);
}
}

Q68: Binary Literals

java

public class Test {


public static void main(String[] args) {
int a = 0b1010;
int b = 0b1100;
[Link](a + b);
}
}

Q69: Octal Literals

java

public class Test {


public static void main(String[] args) {
int a = 010;
int b = 012;
[Link](a + b);
}
}

Q70: Integer Casting


java

public class Test {


public static void main(String[] args) {
int a = 300;
byte b = (byte)a;
[Link](b);
}
}

Point 2.2: Floating Point Types (Questions 71-90)


Q71: Float Precision

java

public class Test {


public static void main(String[] args) {
float f = 3.14f;
[Link](f);
}
}

Q72: Double Precision

java

public class Test {


public static void main(String[] args) {
double d = 3.14159265359;
[Link](d);
}
}

Q73: Float vs Double

java

public class Test {


public static void main(String[] args) {
float f = 1.23456789f;
double d = 1.23456789;
[Link](f);
[Link](d);
}
}
Q74: Float Division

java

public class Test {


public static void main(String[] args) {
float a = 7.0f;
float b = 2.0f;
[Link](a / b);
}
}

Q75: Integer to Float Division

java

public class Test {


public static void main(String[] args) {
int a = 7;
int b = 2;
float result = (float)a / b;
[Link](result);
}
}

Q76: Float Infinity

java

public class Test {


public static void main(String[] args) {
float a = 1.0f;
float b = 0.0f;
[Link](a / b);
}
}

Q77: Float NaN

java
public class Test {
public static void main(String[] args) {
float a = 0.0f;
float b = 0.0f;
[Link](a / b);
}
}

Q78: Float Comparison

java

public class Test {


public static void main(String[] args) {
float a = 0.1f + 0.1f + 0.1f;
float b = 0.3f;
[Link](a == b);
}
}

Q79: Double Exponential

java

public class Test {


public static void main(String[] args) {
double d = 1.23e10;
[Link](d);
}
}

Q80: Float Suffix

java

public class Test {


public static void main(String[] args) {
float f1 = 3.14;
float f2 = 3.14f;
[Link](f1 + f2);
}
}

Q81: Float Overflow


java

public class Test {


public static void main(String[] args) {
float f = Float.MAX_VALUE;
f = f * 2;
[Link](f);
}
}

Q82: Float Underflow

java

public class Test {


public static void main(String[] args) {
float f = Float.MIN_VALUE;
f = f / 2;
[Link](f);
}
}

Q83: Double Special Values

java

public class Test {


public static void main(String[] args) {
[Link](Double.POSITIVE_INFINITY);
[Link](Double.NEGATIVE_INFINITY);
[Link]([Link]);
}
}

Q84: Float Modulo

java

public class Test {


public static void main(String[] args) {
float a = 7.5f;
float b = 2.0f;
[Link](a % b);
}
}
Q85: Float to Integer

java

public class Test {


public static void main(String[] args) {
float f = 3.7f;
int i = (int)f;
[Link](i);
}
}

Q86: Double Rounding

java

public class Test {


public static void main(String[] args) {
double d = 2.5;
[Link]([Link](d));
}
}

Q87: Float Negative Zero

java

public class Test {


public static void main(String[] args) {
float a = 0.0f;
float b = -0.0f;
[Link](a == b);
}
}

Q88: Scientific Notation

java

public class Test {


public static void main(String[] args) {
double d = 6.02e23;
[Link](d);
}
}
Q89: Float Precision Loss

java

public class Test {


public static void main(String[] args) {
float f = 16777216f;
f++;
[Link](f);
}
}

Q90: Mixed Float Operations

java

public class Test {


public static void main(String[] args) {
float f = 2.5f;
double d = 3.5;
[Link](f + d);
}
}

Point 2.3: Character and Boolean Types (Questions 91-110)


Q91: Basic Character

java

public class Test {


public static void main(String[] args) {
char c = 'A';
[Link](c);
}
}

Q92: Character to Integer

java
public class Test {
public static void main(String[] args) {
char c = 'A';
int i = c;
[Link](i);
}
}

Q93: Integer to Character

java

public class Test {


public static void main(String[] args) {
int i = 65;
char c = (char)i;
[Link](c);
}
}

Q94: Character Arithmetic

java

public class Test {


public static void main(String[] args) {
char c = 'A';
c = (char)(c + 1);
[Link](c);
}
}

Q95: Unicode Character

java

public class Test {


public static void main(String[] args) {
char c = '\u0041';
[Link](c);
}
}

Q96: Escape Sequences


java

public class Test {


public static void main(String[] args) {
char tab = '\t';
char newline = '\n';
char quote = '\'';
[Link]("A" + tab + "B" + newline + "C" + quote);
}
}

Q97: Character Range

java

public class Test {


public static void main(String[] args) {
char min = Character.MIN_VALUE;
char max = Character.MAX_VALUE;
[Link]((int)min + " " + (int)max);
}
}

Q98: Boolean True

java

public class Test {


public static void main(String[] args) {
boolean b = true;
[Link](b);
}
}

Q99: Boolean False

java

public class Test {


public static void main(String[] args) {
boolean b = false;
[Link](b);
}
}

Q100: Boolean from Expression


java

public class Test {


public static void main(String[] args) {
boolean b = (5 > 3);
[Link](b);
}
}

Q101: Character Invalid Assignment

java

public class Test {


public static void main(String[] args) {
char c = 65536;
[Link](c);
}
}

Q102: Boolean Invalid Assignment

java

public class Test {


public static void main(String[] args) {
boolean b = 1;
[Link](b);
}
}

Q103: Character String

java

public class Test {


public static void main(String[] args) {
char c = "A";
[Link](c);
}
}

Q104: Character Addition

java
public class Test {
public static void main(String[] args) {
char a = 'A';
char b = 'B';
int sum = a + b;
[Link](sum);
}
}

Q105: Boolean Default

java

public class Test {


static boolean flag;
public static void main(String[] args) {
[Link](flag);
}
}

Q106: Character Array

java

public class Test {


public static void main(String[] args) {
char[] chars = {'H', 'e', 'l', 'l', 'o'};
[Link](chars);
}
}

Q107: Character Comparison

java

public class Test {


public static void main(String[] args) {
char a = 'A';
char b = 'B';
[Link](a < b);
}
}

Q108: Boolean Negation


java

public class Test {


public static void main(String[] args) {
boolean b = true;
[Link](!b);
}
}

Q109: Character Digit

java

public class Test {


public static void main(String[] args) {
char c = '5';
int digit = c - '0';
[Link](digit);
}
}

Q110: Boolean AND

java

public class Test {


public static void main(String[] args) {
boolean a = true;
boolean b = false;
[Link](a && b);
}
}

Point 2.4: String Type (Questions 111-130)


Q111: String Declaration

java

public class Test {


public static void main(String[] args) {
String s = "Hello";
[Link](s);
}
}
Q112: String Concatenation

java

public class Test {


public static void main(String[] args) {
String s1 = "Hello";
String s2 = "World";
[Link](s1 + s2);
}
}

Q113: String with Numbers

java

public class Test {


public static void main(String[] args) {
String s = "Number: " + 10 + 20;
[Link](s);
}
}

Q114: String with Parentheses

java

public class Test {


public static void main(String[] args) {
String s = "Sum: " + (10 + 20);
[Link](s);
}
}

Q115: String Equality

java

public class Test {


public static void main(String[] args) {
String s1 = "Hello";
String s2 = "Hello";
[Link](s1 == s2);
}
}
Q116: String Object Equality

java

public class Test {


public static void main(String[] args) {
String s1 = new String("Hello");
String s

You might also like