Course- BTech Type- Core
Course Code- CSET109 Course Name- Object Oriented Programming Using Java
Year- First Semester- Even Batch- BTech 2nd Semester
Tutorial-2
Tutorial No. Name CO1 CO2 CO3
2 Basics -- --
Objective: The main objective of this tutorial is to learn about the basics of Java language.
2.1 Predict the output of the program:
public class prg {
public static void main(String[] args) {
char a=0x41;
int b = 0x41;
System.out.print(a + "" + b);
System.out.print(","); System.out.print(a+b);
}
}
2.2 Consider the following code and guess the output.
public class Test
{
public static void main(String args[])
{
int i=20 +9- (-12 +4)- (-13) +19;
System.out.println(i);
}
}
2.3 What errors will be reported in following code blocks:
(a) public class Test{
public static int main(String args) {
int a=10;
String s="World";
System.out.println("Hello" + s);
System.out.println(a);
return 0;
}
}
(b) public class Test{
public static int main(String args) {
Int a=10;
string s="World";
System.out.println("Hello" + s);
system.out.println(a);
}
}
2.4 Which line will give error?
public class Test
{
public static void main(String[] args)
{
double d1 = 15f; // s1
double d2 = 25.0; // s2
float f1 = 35f; // s3
float f2 = 45.0; // s4
}
}
2.5 What will be output of below code?
public class Test
{
public static void main(String[] args)
{
int b1 = 10;
int b2 = 5;
int b3 = 0;
System.out.println(b1 & b2 | b2 & b3 | b2);
System.out.println(b1 & b2 | b2 & b3 | b2 | b1 );
}
}
2.6 What is output of below code?
public class Test
{
public static void main(String[] args)
{
int x= 4;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( --x > 2 ) && (++y > 2))
{
y++;
x++;
}
}
System.out.println(x + " " + y);
}
}
2.7 What will be output of below code snippets:
(a) public class Test
{
public static void main(String[] args)
{
int x = 90;
switch(x)
{
case 90:
System.out.println("True");
case 65:
System.out.println("False"); break;
}
}
}
(b) public class Test
{
public static void main(String[] args)
{
int x = 90;
switch(x)
{
case 90:
System.out.println("True"); break;
case 65:
System.out.println("False"); break;
}
}
}
(c) public class Test {
public static void main(String[] args)
{
boolean chk2 = 23<4;
switch(chk2){
case true:
System.out.println("0");
case false:
System.out.println("1");
}
}
}