Professional Documents
Culture Documents
QUESTION 1:
Develop an interface ‘Shape’ with suitable methods to set the number of sides of
the shape and calculate the area of the shape. Create a class ‘Square’ using Shape
and add circumference calculation to the Square class. Then inherit a new class
‘Cube’ from Square by adding the volume calculations. Write a Java program to
test them
CODE:
package prj;
interface Shape{
void no_of_side();
void area();
}
class square implements Shape
{
int a = 0;
double ar = 0;
@Override
public void no_of_side()
{
a = 5;
}
@Override
public void area()
{
ar = 4 * a;
System.out.println("Circumference of Square:"+ar);
}
}
class cube extends square
{
int l = 0;
double ar;
public void input()
{
super.no_of_side();
l = 5;
}
public void volume()
{
super.area();
ar = l * l * l;
System.out.println("Volume of Cube:"+ar);
}
}
public class labfat {
public static void main(String[] args)
{
cube obj = new cube();
obj.input();
obj.volume();
}
}
OUTPUT:
QUESTION 2:
Write a simple Java program which connects to the underlying student database
created in MySQL using JDBC objects to display the student’s details.
CODE:
package javaDB;
import java.sql.*;
public class javadb {
} catch(SQLException ex) {
ex.printStackTrace();
}
}
}
OUTPUT