Cia Java
Cia Java
PART - A
12. Interpret the reason why multiple inheritance in not supported in java.
15. Construct the Regex for the following constraint. The string should consist of only lowercase
and uppercase letters (no numbers or symbols). The string should end in s.
16. Can you call one constructor from another if a class has multiple constructors? Justify.
17. Experiment the concept of method overloading and method overriding in Java with a
sample code.
18. Indicate the use of Assert keyword in Java.
Page 1 of 11
Illustrate the concept of Encapsulation.
24. Write about the concept of interface. Give a real world example
31. Build a Java program to print the area of circle by getting radius as input from the user.
Creating a class named 'Circle' having a method to calculate and print the area.
import java.util.regex.*;
class TestRegEx{
public static void main(String args[])
{
Page 2 of 11
Pattern p = Pattern.compile(".ech");
Matcher m = p.matcher("tech");
boolean b = m.matches();
System.out.println(b);
}
}
34. Predict the output:
class Test
{
public static void main(String args[])
{ System.out.println(fun()); }
static int fun()
{ static int x= 0;
return ++x; }
}
35. Explain how does Java achieve runtime polymorphism.
PART B
1. Examine the concepts of OOPS with suitable example and write a Java program to:
Create class money with two attributes:
int rupee
int paisa
Include getters, setters
Create the main class and initialize the values for the data members
Get two amounts and print their sum.
Input Format
The input consists of two amounts.
Rupee and Paisa are separated by a space.
Output Format
The output prints the total sum.
Refer sample input and output for formatting specifications.
Sample Input
50 85
42 65
Page 3 of 11
Sample Output
93.50
3. Explain the types of inheritance in java with example program for each type.
4. Construct a Java program to separate consonants and vowels from a given string.
Input Format
The input must be a string
Output Format
Refer the sample output
Sample Input
coimbatore
Sample Output
Original String: coimbatore
Separate consonants and vowels of the said string: cmbtroiaoe
5. Write a java program that creates an abstract class called "Shape". This class should have the
following methods:
abstract void rectangleArea();
i abstract void squareArea();
abstract void circleArea();
Then, create a class called "Area" that extends the "Shape" class. This class should calculate
and print
the area of all shapes.
Finally, create a Main class that gets the inputs and passes them to the appropriate methods.
Input Format
The first line of the input consists of the length and breadth.
The second line consists of the side.
The third line consists of the radius.
Output Format
The output prints the area of a rectangle, square, and circle.
Sample Input
10 20
45
Sample Output
200
16
78.54
6. Explain the role of interface in Java while implementing multiple inheritance in java
7. Write a java program to demonstrate hierarchical and multiple inheritance using interfaces.
8. Write a java program finding data type of user input using Regular Expression.
Input Format
The input consists of different inputs of integer, string, double and date with different formats.
Date formats :
1. dd/mm/yyyy : eg: 01/12/2022
2. mm/dd/yyyy : eg: 12/24/2022
Page 4 of 11
3. dd-mon-yy : eg: 01-apr-22
4. dd-mon-yyyy : eg: 01-apr-2022
5. dd-month-yy: eg:01-april-22
6. dd-month-yyyy: eg: 01-april-2022
Output Format
The output prints the value with the appropriate datatype. Refer to the sample input and output
for the formatting specifications.
Sample Input
100
Sample Output
The datat ype of 100 is: java.lang.Integer
9. Explain the concepts of OOPS with suitable example and write a Java program to:
Create a parent class that consists of two methods m1 and m2.
m1 doesn't take any arguments and it just prints from parent.
m2 takes an integer value as parameter and prints the same.
Create a child class that extends parent class and override its methods.
m1 doesn't take any arguments and it just prints from child.
m2 takes an integer value as parameter and prints the same.
In the main class, create objects for the above classes and call the corresponding methods.
Input Format
The input consists of the integer value for both the classes separated by a space.
Output Format
The output displays the result. Refer sample output.
Constraints
integers only.
Sample Input
12
Sample Output
From parent m1()
1
From child m1()
2
10. Relate the concept of instance methods and their relationship with objects. Explain how
instance methods can access instance variables and provide functionality to manipulate them.
Provide an example of a class with instance methods and discuss their usage.
11. Write a Java program to create a class named "Birds" that contains a constructor that prints
"Birds: “Create a class named Parrot, it extends the class Birds. It contains a constructor that
Page 5 of 11
prints "Grey Parrot."
Create class named Cocktail, it extends class Parrot. It contains a constructor that prints "Grey
Cocktail". Create class named Kiwi, it extends class Cocktail. It contains constructor which
prints "Grey Kiwi".
If the input is "Parrot" call the class Parrot.
If the input is "Cocktail" call the class Cocktail.
If the input is "Kiwi" call the class Kiwi.
Input Format
Input consists of a string.
Output Format
Output consists of a string.
Refer to the sample output for your reference.
Sample Input
Kiwi
Sample Output
Birds : Grey Parrot
Grey Cocoktail
Grey Kiwi
12. Build a java program to create an interface called ShapeCalculator" that has a method called
"calc(int n)".
13. Differentiate between classes, abstract classes and Interfaces.
14. Build a java program to get the citizen details like Aadhar number, name, city, state and
country. Define an exception called “NoMatchExcepion” that is thrown when the country
name is not equal to “India”.
15. Explain in detail about constructor overloading with example.
16. Construct a Java program to separate consonants and vowels from a given string.
Input Format
The input must be a string
Output Format
Refer the sample output
Sample Input
coimbatore
Sample Output
Original String: coimbatore
Separate consonants and vowels of the said string: cmbtroiaoe
17. Compare and contrast Method Overloading with Method Overriding in java by supporting
Page 6 of 11
examples.
18. Write a java program that creates an abstract class called "Shape". This class should have the
following methods:
abstract void rectangleArea();
abstract void squareArea();
abstract void circleArea();
Then, create a class called "Area" that extends the "Shape" class. This class should calculate
and print
the area of all shapes.
Finally, create a Main class that gets the inputs and passes them to the appropriate methods.
Input Format
The first line of the input consists of the length and breadth.
The second line consists of the side.
The third line consists of the radius.
Output Format
The output prints the area of a rectangle, square, and circle.
Sample Input
10 20
45
Sample Output
200
16
78.54
19. Explain the role of interface in Java while implementing multiple inheritance in java
20. Write a Java program to move all the uppercase characters to the end of the string.
Note: Create an interface name Case with a method, and the main class should define the
interface method.
Input Format
The first line of the input consists of a string.
Output Format
Display the output as uppercase characters at the end of the string.
Sample Input
REasonBehInd
Sample Output
AsonehndREBI
21. Explain the concepts of OOPS with suitable example and write a Java program to:
Create class money with two attributes:
int rupee
int paisa
Include getters, setters
Create the main class and initialize the values for the data members
Get two amounts and print their sum.
Input Format
Page 7 of 11
The input consists of two amounts.
Rupee and Paisa are separated by a space.
Output Format
The output prints the total sum.
Refer sample input and output for formatting specifications.
Sample Input
50 85
42 65
Sample Output
93.50
22. Explain the behavior of static members (variables and methods) in the context of inheritance in
Java. Discuss how static members are inherited, accessed, and overridden by sub classes.
Provide examples to illustrate the concepts and highlight potential pitfalls when using static
members in an inheritance hierarchy.
23. Build a Java program that create a regular expression to represent all mobile numbers.
1. Should contain exactly 10 digits.
2. The 1st digit should be 7 to 9.
Input Format - The input consists of digits.
Output Format - The output prints the mobile number by checking is it a valid number or an
invalid number.
24. Write a Java program to move all the uppercase characters to the end of the string.
Note: Create an interface name Case with a method, and the main class should define the
interface method.
Input Format
The first line of the input consists of a string.
Output Format
Display the output as uppercase characters at the end of the string.
Sample Input
REasonBehInd
Sample Output
Page 8 of 11
AsonehndREBI
25. Explain the concepts of OOPS with suitable example and write a Java program to:
Create class money with two attributes:
int rupee
int paisa
Include getters, setters
Create the main class and initialize the values for the data members
Get two amounts and print their sum.
Input Format
The input consists of two amounts.
Rupee and Paisa are separated by a space.
Output Format
The output prints the total sum.
Refer sample input and output for formatting specifications.
Sample Input
50 85
42 65
Sample Output
93.50
Page 9 of 11
Page 10 of 11