Professional Documents
Culture Documents
static {
System.out.println("Static Block 1");
num = 68;
}
static {
System.out.println("Static Block 2");
num = 98;
}
}
}
15. WAP to print the number of objects created for a class.
class Object
{
private static int count = 0;
public Object () {
count++;
}
}
16. In Box class, add member function to find values of private variables
class Circle {
private int
radius;
{ this.radius = radius;
{ return radius;
double area;
area=3.14*radius*radi
Circle(40);
}
17. In Box class, add member function to print volume of box.
class Box
private int
length; private
int height;
{ return length;
{ return width;
{ return height;
this.width = width;
this.height = height;
60);
System.out.println("Length: " +
+ box.getWidth()); System.out.println("Height:
}
18. In Box class, add getter and setter methods for private variables.
class Box
private int
length; private
int height;
this.width = width;
this.height =
height;
{ return length;
{ return width;
{ this.width = width;
{ return height;
}
60);
System.out.println("Length: " +
+ box.getWidth()); System.out.println("Height:
" + box.getHeight());
}
19. Execute Inner class-related program conducted during Saturday session
class OuterClass {
private int
outerValue; class
InnerClass {
outerValue);
outerValue) { this.outerValue =
outerValue;
InnerClass(); inner.innerValue =
10;
OuterClass();
outer.setOuterValue(20);
InnerClass(); inner.displayOuterValue();
}
}
20. Study questions given in below link:
21. WAP to enter an integer value, a character value, a double value and store
import java.util.Scanner;
public class
WrapperExample {
Scanner(System.in);
System.out.print("Enter an integer
intWrapper);
System.out.print("Enter a character
scanner.next().charAt(0);
Character charWrapper =
Character.valueOf(charValue);
charWrapper);
scanner.nextDouble();
Double doubleWrapper =
Double.valueOf(doubleValue);
doubleWrapper); scanner.close();
}
22. WAP to print ASCII values
char c = (char) i;
}
23. WAP to check if given number is palindrome or not
class Palindrome{
if (isPalindrome(number))
else
}
}
24. WAP to check if given String is palindrome or not
class Palindrome{
if (str.charAt(i) != str.charAt(length - i -
return true;
if (isPalindrome(str)) {
} else {
}
25. WAP to create 2 variables as final and try to change their value to see the error.
}
26. WAP to perform linear search.
if (array[i] == key)
{ return i;
return -1;
5};
int key = 3;
} else {
}
27. WAP to swap 2 numbers using call by value in Java. How swapping using
public class
Swap {
b) { int temp = a;
a = b;
b = temp;
int y = 20;
+ y); swap(x,y);
}
28. WAP to demonstrate ragged array in Java.
public class
RaggedArray {
int[2];
j++) { raggedArray[i][j] = i + j;
j++) { System.out.print(raggedArray[i][j]
+ " ");
System.out.println();