0% found this document useful (0 votes)
5 views4 pages

Tutorial 4

This document outlines a tutorial for a BTech course on Object Oriented Programming Using Java, focusing on wrapper classes, arrays, and method invocation. It includes various coding exercises with questions about the output of Java code snippets. The tutorial aims to enhance understanding of basic Java concepts through practical coding examples.

Uploaded by

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

Tutorial 4

This document outlines a tutorial for a BTech course on Object Oriented Programming Using Java, focusing on wrapper classes, arrays, and method invocation. It includes various coding exercises with questions about the output of Java code snippets. The tutorial aims to enhance understanding of basic Java concepts through practical coding examples.

Uploaded by

guptanaman1006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

School of Computer Science Engineering and Technology

Course- BTech Type- Core


Course Code- CSET109 Course Name- Object Oriented Programming Using Java
Year- First Semester- Even Batch- BTech 2nd Semester

Tutorial-4

Tutorial No. Name CO1 CO2 CO3


4 Basics  -- --

Objective: The main objective of this tutorial is to learn about the basics of Wrapper classes, arrays
and user-defined method invocation in java language.

4.1 Compile and run the below code? Mention the reason?

public class WrapDemo


{
public static void main(String[] args)
{
int i1=10;
Integer i2=Integer.valueOf(0xA);
if(i1==i2)
{
System.out.print("\t i1 and i2 are same");
}
else
{
System.out.print("\t i1 and i2 are not same");
}
}
}

4.2 Which of following will work and why?

public class Test


{
public static void main(String[] args)
{
byte grade = 128;
int marks = 50;
float price = 8.6;
double rate = 50.5;
Integer m1 = Integer.valueOf(marks);
Byte g1 = Byte.valueOf(grade);
Float f1 = Float.valueOf(price);
Double r1 = Double.valueOf(rate);
System.out.println("Values of Wrapper objects (printing as objects)");
System.out.println("Byte object g1: " + g1);
School of Computer Science Engineering and Technology

System.out.println("Integer object m1: " + m1);


System.out.println("Float object f1: " + f1);
System.out.println("Double object r1: " + r1);
}
}

4.3 What will be output of below code?

public class Test


{
public static void main(String[] args)
{
Boolean b1 = false;
Boolean b2;

b2 = b1;
if (!b2)
{
b2 = true;
System.out.print("x ");
}
if (b1 | b2)
{
System.out.print("y ");
}
if(b1 || !b2)
System.out.println("z");

}
}

4.4 What will be the Output of the below code:

import java.util.*;

public class prob4 {


public static void main(String []args) {
int arr[]={5,3,1,6,2};
int val=0;
val = arr[0];
for(int i=1; i<arr.length;i++) {
if (val < arr[i])
val = arr[i];
}
System.out.println(val);
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
}
School of Computer Science Engineering and Technology

4.5 What is the output of following code?

import java.util.*;

class prob4 {
public static void main(String args[]) {
int arr1[] = {11, 22, 33};
int arr2[] = {11, 22, 33, 44, 55};
int ptr[];
ptr = arr1;
arr1 = arr2;
arr2 = ptr;
System.out.print(arr1.length + " ");
System.out.println(Arrays.toString(arr1));
System.out.print(arr2.length+" "+Arrays.toString(arr2));
}
}

4.6 What is the output of following code?

class prob4 {
public static void main(String[] args)
{
int arr[] = { 11, 22, 33 };
for (int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");

System.out.println();

int arr2[] = new int[3];


arr2[] = { 11, 22, 33 };
for (int i = 0; i < arr2.length; i++)
System.out.print(arr2[i] + " ");
}
}

4.7 What is the result of the following code?

class prob4 {
public static void main(String[] args)
{
int arr[] = new int[5];
int arr2[] = new int['a'];
byte bt = 10;
int arr3[] = new int[bt];
System.out.println(arr.length);
System.out.println(arr2.length);
System.out.println(arr3.length);
}
}
School of Computer Science Engineering and Technology

4.8 What will be the output of the following program?

class prob4 {
public static void main(String[] args)
{
String str[] = { "Geeks", "for", "Geeks" };
System.out.println(str.length);
System.out.println(str[0].length);
}
}

4.9 What will be output for following code?

import java.util.*;
public class Main {
public static void main(String[] args) {
}

public static void abc()


{
int x=1, i=2; do
{
x*=i;
}while(++i<=5);
System.out.println(x);
}
}

4.10 What is output of below code?

public
class Main {
public
int foo() { return 10; }
public
char foo() { return 'a'; }
public
static void main(String args[]) {
foo();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy