Prof. Name: DARSHAN PATIL Class/sem:SY.
BCA/ Sem-IV (2023-2024)
Course Code:CMP512 Subject Name: JAVA
INDEX
PRACTICAL ACTIVITIES DATE SIGNATUR
NO. E
1. i. Write a Java class to swap two numbers
without using third
variable.
ii. Write a Java Program to determine
reverse the number
iii. Write a Java class to print the Fibonacci
sequence till 100
iv. Write a Java Program to determine
whether the number is
Armstrong or not.
v. Write a Java Program to determine
whether the number is
prime or no
2. [Link] a Java program for the following
scenario: Run a loop
from 1 to 100, while looping when the
number is even print its
square and when the number is odd print its
cube.
ii. Write a Java program to print the
following Floyd Triangle
1
01
101
0101
iii. Write a Java Program to print following
12345
1234
1
123
12
1
3. i. Write a Java class Employee with
variables name, age,
gender write setter and getter methods for it.
ii. Write a class mobile with methods call()
and sms(). Write a
class Demo and access it.
iii. Write a class MathDemo with methods
square() with one
parameter and add() with two parameters.
Call these methods
to get the output
4. Write a Java class for following
methods
display() -- Display number from 1 to 100
using while loop in Java
fibonacci() -- Prints Fibonacci series till 100
5. Write a class Automobile with default
constructor, write a class
Plane which extends Automobile and has a
default as well as
parameterized constructor, write a class
Airbus with a default
constructor which extends Plane.
6. [Link] a Java Program to convert “25” to
Primitive as well
as Wrapper.
[Link] a Java program to convert 110011
to decimal value.
7. Write a Java Program to convert the “59” to
Primitive float (without
using Constructor of Float)
8. Write a class User with abstract methods
pay() and receive(),
later make two concrete class GoldUser and
2
SilverUser, override
the abstract method.
9. Write a Java program to write the following,
class A with method
m1( ) and m2( ) and write a class B with
methods m3( ) and m4( ),
Override the methods of A in class B
10. i. Write an abstract class Car with methods
start() and stop().
[Link] a class Santro and Audi and
override the methods.
[Link] two interfaces SportsCar and
CommercialCar and implement the
appropriate interface on the appropriate
class
made in example 1.
11. [Link] an Interface CE which have methods
call(), sms (), Make
another interface ISO which have methods
radiation() and
sound().
[Link] two classes IPhone and Galaxy and
make them implement both the interfaces.
[Link] a Java program to make a package
[Link], make classes Circle and Square
in the same package
12. [Link] a Java Program to make an
Exception [Link] user passes
some age and if age is less than 18 throw
this Exception.
ii. Create an Exception
StringNotPalindromeException. Write a
class with method which throws this
Exception when String
passed is not palindrome
13. [Link] a Java program to determine the
number of vowels in a String
ii. Write a Java program for separate hours,
3
minutes and seconds from following string
01:23:
14. i. Write a Java Program to store the
following data, in the collection you feel
will suite best.
Name- Tom
Email- tom@[Link]
Phone:9988776655
ii. Write a Java Program to find the
minimum value in Vector [8,9,1,3,4].
iii. Write a Java Program to find the number
of String starting with „S‟ from following
TreeSet [ Smith, Alex , Tom, Steve,
Mark, Sammy]
15. Sort the given list of objects in order of their
email Contact:id, name, email, phone
4
Java (CMP512)
Practical No.1
Aim: [Link] a Java class to swap two numbers without using a third variable.
ii. Write a Java Program to determine the reverse of the number.
iii. Write a Java class to print the Fibonacci sequence till 100.
iv. Write a Java Program to determine whether the number is Armstrong or not.
v. Write a Java Program to determine whether the number is prime or not.
Theory:
i. Swapping two numbers without using a third variable: A simple way to do this is to use a third variable
as a temporary holder for one of the values while we assign the other value to the other variable.
ii. Reverse of a number:The reverse of a number is obtained by reversing the order of its digits. For
example, the reverse of 1234 is 4321. Reversing a number can be useful in various applications, such as
checking for palindromes or sorting numbers.
iii. Fibonacci sequence:The Fibonacci sequence is a series of numbers in which each number is the sum of
the two preceding ones, usually starting with 0 and 1. That is, the sequence goes: 0, 1, 1, 2, 3, 5, 8, 13, 21,
34, and so forth.
iv. Armstrong number:An Armstrong number is a positive integer that is equal to the sum of its own digits
each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1^3
+ 5^3 + 3^3 = 153. Armstrong numbers are also known as narcissistic numbers.
v. Prime number:A prime number is a positive integer greater than 1 that has no positive integer divisors
other than 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11, and so on.
5
Source code:
1.
public class SwapNumbers {
public static void main(String[] args) {
int num1 = 5, num2 = 10;
[Link]("Before swapping: num1 = " + num1 + ", num2 = " + num2);
num1 = num1 + num2; // num1 now becomes 15
num2 = num1 - num2; // num2 now becomes 5
num1 = num1 - num2; // num1 now becomes 10
[Link]("After swapping: num1 = " + num1 + ", num2 = " + num2);
}
}
2.
public class ReverseNumber {
public static void main(String[] args) {
int num = 12345, reverse = 0, remainder;
while (num != 0) {
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
[Link]("Reverse of the number: " + reverse);
}
}
3.
public class FibonacciSequence {
public static void main(String[] args) {
int num1 = 0, num2 = 1, num3, count = 0;
[Link](num1 + " " + num2 + " "); // printing 0 and 1
while (count < 98) { // as we have already printed two numbers
num3 = num1 + num2;
if (num3 > 100) break;
[Link](num3 + " ");
num1 = num2;
num2 = num3;
count++;
}
6
}
}
4.
import [Link];
public class ArmstrongNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
[Link]();
int numOfDigits = numOfDigits(num);
int sum = 0;
int temp = num;
while (temp != 0) {
int digit = temp % 10;
sum += [Link](digit, numOfDigits);
temp /= 10;
}
if (sum == num) {
[Link](num + " is an Armstrong number.");
} else {
[Link](num + " is not an Armstrong number.");
}
}
public static int numOfDigits(int num) {
int count = 0;
while (num != 0) {
num /= 10;
count++;
}
return count;
}
}
7
5.
public class PrimeNumber {
public static void main(String[] args) {
int num = 17, i, flag = 0;
for (i = 2; i <= num / 2; i++) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
[Link](num + " is a prime number.");
else
[Link](num + " is not a prime number.");
}
}
Output:
1. 2.
8
3.
4.
5.
9
Conclusion:Thus Practical of Implementation of Java class to swap two numbers without using a third
variable Java Program to determine the reverse of the number. Java class to print the Fibonacci sequence
till 100 Java Program to determine whether the number is Armstrong or not Java Program to determine
whether the number is prime or not completed successfully.
Prn no. Signature:
10
JAVA (CMP512)
Practical No.2
Aim: [Link] a Java program for the following scenario: Run a loop from 1 to 100, while looping when
the number is even, print its square and when the number is odd print its cube.
ii. Write a Java program to print the following Floyd Triangle
1
01
101
0101
iii. Write a Java Program to print following
12345
1234
123
12
1
Theory:
[Link] are used in programming to repeat a block of code multiple times. Java provides three types of
loops: for loop, while loop, and do-while loop.
The for loop is used when the number of iterations is known beforehand.
syntax:for (initialization; condition; increment/decrement) {
// code to be executed
}
[Link] Floyd Triangle (also known as Pascal's Triangle modified) can be printed using nested loops in
[Link] pattern can be printed using nested loops in Java. The outer loop iterates over the rows, and the
inner loop iterates over the columns in the current row. The number to be printed in the current cell is
determined based on the current row and column numbers.
[Link] statements are used in programming to execute different blocks of code based on certain
conditions. Java provides two types of conditional statements: if statement and switch statement.
The if statement is used to execute a block of code if a certain condition is true Java provides two types of
conditional statements: if statement and switch statement
11
Syntax:
[Link] (condition) {
// code to be executed if condition is true
} else {
// code to be executed if condition is false
}
[Link] (expression) {
case value1:
// code to be executed if expression is equal to value1
break;
case value2:
// code to be executed if expression is equal to value2
break;
// more cases as needed
default:
// code to be executed if expression is not equal to any of the values
}
Source code:
1.
public class Main {
public static void main(String[] args) {
for(int i = 1; i <= 100; i++) {
if(i % 2 == 0) {
[Link]("Square of " + i + " is " + (i*i));
} else {
[Link]("Cube of " + i + " is " + (i*i*i));
}
}
}
}
12
2.
public class Main {
public static void main(String[] args) {
int number = 1;
for(int row = 1; row <= 5; row++) {
for(int col = 1; col <= row; col++) {
[Link](number + " ");
number = number == 0 ? 1 : 0;
}
[Link]();
}
}
}
3.
public class Main {
public static void main(String[] args) {
int maxRows = 5;
for(int row = maxRows; row >= 1; row--) {
for(int col = 1; col <= row; col++) {
[Link](col + " ");
}
[Link]();
}
for(int row = 2; row <= maxRows; row++) {
for(int col = 1; col <= row; col++) {
[Link](col + " ");
}
[Link]();
}
}
}
13
Output:
1.
2.
14
3.
Conclusion:Thus Practical Implementation of Java program for the following scenario: Run a loop
from 1 to 100, while looping when the number is even, print its square and when the number is odd print
its cube. Java program to print the following Floyd Triangle is completed successfully.
15
Prn no.
signature:
JAVA(CMP512)
Practical no. 3
Aim:i. Write a Java class Employee with variables name, age, gender write setter and getter
methods for it.
ii. Write a class mobile with methods call() and sms(). Write a
class Demo and access it.
iii. Write a class MathDemo with methods square() with one
parameter and add() with two parameters. Call these methods
to get the output.
Theory:In the above examples, we have created different classes to encapsulate related
variables and methods. This is a fundamental concept in object-oriented programming (OOP)
and helps in organizing the code, promoting reusability, and hiding implementation details.
In the Employee class, we have defined private variables name, age, and gender, and provided
public setter and getter methods to access and modify these variables. This is an example of
encapsulation, where the internal state of an object is hidden from the outside world, and can
only be accessed through well-defined interfaces (methods).
In the Mobile class, we have defined methods call() and sms() that perform specific actions. In
the Demo class, we have created an instance of Mobile and called these methods to demonstrate
how objects can be used to perform actions.
In the MathDemo class, we have defined methods square() and add() that perform mathematical
operations. In the Demo class, we have created an instance of MathDemo and called these
methods to demonstrate how objects can be used to perform calculations.
16
These examples illustrate the principles of OOP, including encapsulation, inheritance,
polymorphism, and abstraction. By using these principles, we can create modular, maintainable,
and extensible code that is easier to understand and modify.
Source code:
1.
class Employee
{
// class member variable
private int eId;
private String eName;
private String eDesignation;
private String eCompany;
public int getEmpId()
{
return eId;
}
public void setEmpId(final int eId)
{
[Link] = eId;
}
public String getEmpName()
{
return eName;
}
public void setEmpName(final String eName)
{
// Validating the employee's name and
// throwing an exception if the name is null or its length is less than or equal to 0.
if(eName == null || [Link]() <= 0)
{
throw new IllegalArgumentException();
}
[Link] = eName;
}
17
public String getEmpDesignation()
{
return eDesignation;
}
public void setEmpDesignation(final String eDesignation)
{
[Link] = eDesignation;
}
public String getEmpCompany()
{
return eCompany;
}
public void setEmpCompany(final String eCompany)
{
[Link] = eCompany;
}
// for printing the values
@Override
public String toString()
{
String str = "Employee: [id = " + getEmpId() + ", name = " + getEmpName() + ",
designation = " + getEmpDesignation() + ", company = " + getEmpCompany() + "]";
return str;
}
}
// Main class.
public class GetterSetterExample1
{
// main method
public static void main(String argvs[])
{
// Creating an object of the Employee class
final Employee emp = new Employee();
// the employee details are getting set using the setter methods.
[Link](107);
[Link]("Kathy");
[Link]("Software Tester");
[Link]("XYZ Corporation");
// Displaying the details of the employee details using the
18
// 'toString()' method, which uses the getter methods
[Link]([Link]());
}
}
Output:
1.
Conclusion:Java class Employee with variables name, age, gender write setter and getter
methods for it. class mobile with methods call() and sms()class Demo and access it class
MathDemo with methods square() with one parameter and add() with two parameters. Call these
methods to get the output completed successfully.
19
Prn no. Signature:
JAVA(CMP512)
Practical no.4
Aim:Write a Java class for following methods display() -- Display number from 1 to 100 using
while loop in Java fibonacci() -- Prints Fibonacci series till 100.
Theory:The display() method uses a while loop to iterate from 1 to 100 and prints each
number. The fibonacci() method calculates the Fibonacci series up to the 100th term or when the
next term exceeds 100. It prints each term of the series separated by a space. The main() method
is the entry point of the program, which calls the display() and fibonacci() methods to execute
their [Link] Fibonacci series is a sequence of numbers where each number is the sum
of the two preceding ones, usually starting with 0 and 1. The series is named after the Italian
mathematician Leonardo of Pisa, known as Fibonacci.
F(0) = 0, F(1) = 1
20
F(n) = F(n-1) + F(n-2)
Source code:
public class NumberDisplay {
// Method to display numbers from 1 to 100 using a while loop
public void display() {
int number = 1;
while (number <= 100) {
[Link](number);
number++;
}
}
// Method to print the Fibonacci series up to the 100th term
public void fibonacci() {
int firstTerm = 0, secondTerm = 1, nextTerm = firstTerm + secondTerm;
[Link]("Fibonacci Series up to the 100th term:");
while (nextTerm <= 100) {
[Link](firstTerm + " ");
firstTerm = secondTerm;
secondTerm = nextTerm;
nextTerm = firstTerm + secondTerm;
}
// Print the last term if it's less than or equal to 100
if (firstTerm <= 100) {
[Link](firstTerm + " ");
}
if (secondTerm <= 100) {
[Link](secondTerm + " ");
}
[Link](); // For a new line at the end
}
// Main method to run the program
public static void main(String[] args) {
NumberDisplay numberDisplay = new NumberDisplay();
// Display numbers from 1 to 100
21
[Link]("Numbers from 1 to 100:");
[Link]();
// Print the Fibonacci series up to the 100th term
[Link]();
}
}
Output:
Conclusion:Java class for following methods display() -- Display number from 1 to 100 using
while loop in Java fibonacci() -- Prints Fibonacci series till 100 is completed successfully.
22
Prn no. signature:
JAVA(CMP512)
Practical no.5
Aim:Write a class Automobile with default constructor, write a class
Plane which extends Automobile and has a default as well as
parameterized constructor, write a class Airbus with a default
constructor which extends Plane.
Theory:The Automobile class has a default constructor that prints a message when it is called.
The Plane class extends the Automobile class and has a default constructor that prints a message
when it is called. It also has a parameterized constructor that takes a string argument and prints a
message with the argument [Link] Airbus class extends the Plane class and has a default
constructor that prints a message when it is [Link] the main class, objects of the classes
Automobile, Plane, and Airbus are created using their default constructors. An object of the
Plane class is also created using its parameterized [Link] the objects are created, the
constructors are called in the order of inheritance, i.e., the constructor of the superclass is called
before the constructor of the [Link], when an object of the Airbus class is created,
the default constructor of the Plane class is called first, followed by the default constructor of the
Airbus
Source code:
class Main {
private String name;
// constructor
Main() {
[Link]("Constructor Called:");
name = "Java student";
23
}
public static void main(String[] args) {
// constructor is invoked while
// creating an object of the Main class
Main obj = new Main();
[Link]("The name is " + [Link]);
}
}
Output:
Conclusion: class Automobile with default constructor, a class Plane which extends
Automobile and has a default as well as parameterized constructor, class Airbus with a default
constructor which extends Plane is completed successfully.
24
Prn no. Signature:
JAVA( CMP512)
Practical no. 6
Aim:.Write a Java Program to convert “25” to Primitive as well
as Wrapper.
[Link] a Java program to convert 110011 to decimal value.
Theory:The [Link]() method is used to convert a string to a primitive integer value.
The second argument of this method specifies the base of the number system. For example, if
you specify 2, it will interpret the string as a binary number.
The [Link]() method is used to convert a string to a wrapper integer value.
In Java, the Integer class provides several methods for converting numbers between different
bases. The parseInt() method is used to convert a string representation of a number in a particular
base to its equivalent integer value. The second argument to this method is the base of the
number system. For example, to convert a binary number to decimal, we pass 2 as the second
[Link] valueOf() method is used to convert a string representation of a number to its
corresponding wrapper object. This method returns an Integer object for an integer value.
When we convert a string to a primitive int, the value is automatically unboxed to a primitive
value. Similarly, when we convert a string to a Integer wrapper, the value is automatically boxed
to a wrapper object
Source code: 1.
public class Main {
public static void main(String[] args) {
String str = "25";
// Converting string to primitive type
25
int primitive = [Link](str);
[Link]("Primitive: " + primitive);
// Converting string to wrapper type
Integer wrapper = [Link](str);
[Link]("Wrapper: " + wrapper);
}
}
2.
public class Main {
public static void main(String[] args) {
String binary = "110011";
// Converting binary to decimal
int decimal = [Link](binary, 2);
[Link]("Decimal: " + decimal);
}
}
Output:
1.
26
2.
Conclusion:. Java Program to convert “25” to Primitive as well as [Link] program to
convert 110011 to decimal value is completed successfully.
27
Prn no. Signature:
JAVA(CMP512)
Practical no. 7
Aim:Write a Java Program to convert the “59” to Primitive float (without
using Constructor of Float)
Theory: The parseFloat() method of the Float class is used to convert a string into a primitive
float [Link] parseFloat() method takes a string argument and returns a primitive float value.
If the string cannot be converted to a float value, then the method throws a
[Link] our example, we use this method to convert the string "59" to a
primitive float [Link] "59" is a valid float value, the method returns the float value 59.0.
We store this value in a float variable floatValue and print it using [Link]().
Source code:
public class Main {
public static void main(String[] args) {
String str = "59";
float floatValue = [Link](str);
[Link]("The float value of " + str + " is: " + floatValue);
}
}
28
Output:
Conclusion: To convert the “59” to Primitive float (without using Constructor of Float) is
completed successfully.
29
Prn no. signature:
JAVA(CMP512)
Practical no. 8
Aim: Write a class User with abstract methods pay() and receive(),
later make two concrete class GoldUser and SilverUser, override
the abstract method.
Theory:In Java, an abstract class is a class that cannot be instantiated and is typically used as a
base class for other classes. An abstract class can contain both abstract and concrete methods
(methods with and without a body, respectively). Abstract methods are declared using the
abstract keyword and do not have a body. Concrete methods, on the other hand, have a body and
provide an implementation for the method. When a class extends an abstract class, it must
provide concrete implementations for all of the abstract methods in the superclass. If a class does
not provide an implementation for an abstract method, it must also be declared as abstract.
In this example, the User class is declared as abstract and contains two abstract methods pay()
and receive(). The GoldUser and SilverUser classes extend User and provide concrete
implementations for these [Link] declaring the User class as abstract, we ensure that it
cannot be instantiated directly and that any classes that extend it must provide concrete
implementations for the abstract methods. This allows us to define a common interface for all
User objects, while still allowing for different implementations of the pay() and receive()
methods for different types of users.
Source code:
// Abstract User class
abstract class User {
// Abstract methods
30
abstract void pay();
abstract void receive();
}
// Concrete GoldUser class
class GoldUser extends User {
public void pay() {
[Link]("GoldUser is paying...");
}
public void receive() {
[Link]("GoldUser is receiving...");
}
}
// Concrete SilverUser class
class SilverUser extends User {
public void pay() {
[Link]("SilverUser is paying...");
}
public void receive() {
[Link]("SilverUser is receiving...");
}
}
// Main class
public class Main {
public static void main(String[] args) {
// Create instances of GoldUser and SilverUser
User goldUser = new GoldUser();
User silverUser = new SilverUser();
// Call pay() and receive() methods on GoldUser
[Link]();
[Link]();
// Call pay() and receive() methods on SilverUser
[Link]();
[Link]();
}
}
31
Output:
Conclusion:Write a class User with abstract methods pay() and receive(), later make two
concrete class GoldUser and SilverUser, override the abstract method.
32
Prn no. Signature:
JAVA(CMP512)
Practical no. 9
Aim: Write an abstract class Car with methods start() and stop().
Write a class Santro and Audi and override the methods.
Write two interfaces SportsCar and CommercialCar and implement the appropriate interface on
the appropriate class made in example 1
Theory:class B extends class A and overrides its methods m1() and m2(). The @Override
annotation is used to indicate that the methods are intended to override methods in the
superclass. If a method with the @Override annotation does not actually override a method in the
superclass, the compiler will generate an error.
Source code:
class A {
void m1() {
[Link]("Inside m1 of class A");
}
void m2() {
[Link]("Inside m2 of class A");
}
}
class B extends A {
@Override
void m1() {
[Link]("Inside m1 of class B");
}
@Override
33
void m2() {
[Link]("Inside m2 of class B");
}
void m3() {
[Link]("Inside m3 of class B");
}
void m4() {
[Link]("Inside m4 of class B");
}
}
public class Main {
public static void main(String[] args) {
B obj = new B();
obj.m1();
obj.m2();
obj.m3();
obj.m4();
}
}
Output:
Conclusion:To write the following, class A with method m1( ) and m2( ) and write a class B
with methods m3( ) and m4( ), Override the methods of A in class B is completed successfully.
34
Prn no. Signature:
JAVA(CMP512)
Practical no. 10
Aim:Write an abstract class Car with methods start() and stop().
Write a class Santro and Audi and override the methods.
Write two interfaces SportsCar and CommercialCar and implement the appropriate interface on
the appropriate class made in example
Theory: The abstract class "Vehicle" has two abstract methods: startEngine() and
stopEngine(). The subclasses Car and Motorcycle extend the "Vehicle" class and provide their
own implementations for these abstract [Link] "Car" class starts and stops the car's engine,
while the Motorcycle class starts and stops the motorcycle's [Link] the main method, we
create instances of Car and Motorcycle. We then call the startEngine() and stopEngine() methods
on each object to start and stop the engines for both vehicle types.
35
Source code:
//[Link]
abstract class Vehicle {
public abstract void startEngine();
public abstract void stopEngine();
}
//[Link]
class Car extends Vehicle {
@Override
public void startEngine() {
[Link]("Car: Starting the engine...");
}
@Override
public void stopEngine() {
[Link]("Car: Stopping the engine...");
}
}
//[Link]
class Motorcycle extends Vehicle {
@Override
public void startEngine() {
[Link]("Motorcycle: Starting the engine...");
}
@Override
public void stopEngine() {
[Link]("Motorcycle: Stopping the engine...");
}
}
//[Link]
public class Main {
public static void main(String[] args) {
Vehicle car = new Car();
Vehicle motorcycle = new Motorcycle();
36
[Link]();
[Link]();
[Link]();
[Link]();
}
}
Output:
Conclusion:abstract class Car with methods start() and stop(). class Santro and Audi and
override the [Link] interfaces SportsCar and CommercialCar and implement the
appropriate interface on the appropriate class made in example is completed successfully.
37
Prn no. Signature:
Practical no. 11
Aim: Make an Interface CE which have methods call(), sms (), Make
another interface ISO which have methods radiation() and
sound(). Make two classes IPhone and Galaxy and make them
implement both the [Link] a Java program to make a package [Link], make
classes Circle and Square in the same package.
Theory:
Demonstrates how to create an interface CE with methods call() and sms(), another interface ISO
with methods radiation() and sound(), and two classes IPhone and Galaxy that implement both
interfaces. I've also included a package [Link] with classes Circle and Square.
Source code:
// Interface CE
interface CE {
void call();
void sms();
}
// Interface ISO
interface ISO {
void radiation();
void sound();
}
// Class IPhone implementing both interfaces
class IPhone implements CE, ISO {
38
@Override
public void call() {
[Link]("IPhone is calling...");
}
@Override
public void sms() {
[Link]("Sending SMS from IPhone...");
}
@Override
public void radiation() {
[Link]("IPhone is emitting radiation...");
}
@Override
public void sound() {
[Link]("IPhone is making sound...");
}
}
// Class Galaxy implementing both interfaces
class Galaxy implements CE, ISO {
@Override
public void call() {
[Link]("Galaxy is calling...");
}
@Override
public void sms() {
[Link]("Sending SMS from Galaxy...");
}
@Override
public void radiation() {
[Link]("Galaxy is emitting radiation...");
}
@Override
public void sound() {
[Link]("Galaxy is making sound...");
}
39
}
// Main class
public class Main {
public static void main(String[] args) {
IPhone iphone = new IPhone();
Galaxy galaxy = new Galaxy();
// Testing methods
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
}
}
Output:
40
Conclusion:Make an Interface CE which have methods call(), sms (), Make
another interface ISO which have methods radiation() and sound(). Make two classes IPhone and
Galaxy and make them implement both the [Link] make a package [Link], make
classes Circle and Square in the same package is completed successfully.
Prn no. Signature:
41
42