Name : SRAVYA PARIDALA
Batch : B3
Enrollment No. : A70405221162
Aim : To pass values to the function using command line argument
PROGRAM:
package com.company;
import java.util.Scanner;
public class exp1 {
public static void main(String args[]) {
args = new String[3];
Scanner sc = new Scanner(System.in);
for(int i=0;i<args.length;i++){
System.out.println("input num : " + (i+1));
args[i]= sc.next();
}
int [] a;
a=new int[3];
for(int i=0;i<args.length;i++){
a[i]= Integer.parseInt(args[i]);
}
int x;
x=a[0]+a[1]+a[2];
System.out.println( "sum of all 3 num is : " + x);
}
}
Name : SRAVYA PARIDALA
Enrollment no. : A70405221162
Batch : B3
Aim: Multilevel inheritance and hierarchical inheritance
Program:
class Shape {
public void area(){ System.out.println("Area of Shape");
}
}
class Triangle extends Shape{
public void area(int h, int b) {
System.out.println("area of triangle is " +
(0.5)*b*h);
}
}
//multilevel inheritance
class EquilateralTriangle extends Triangle {
public void area(int h){
System.out.println("area of this triangle is :
"+(0.4275)*h*h);
//hierarchical inheritance
class Circle extends Shape{
public void area(int r){
System.out.println("area of circle is : " +
(3.14)*r*r);
}
}
public class experiment3{
public static void main(String[] args){
EquilateralTriangle T = new
EquilateralTriangle();
//object define
Circle C = new Circle();
T.area(); //methode call
T.area(6,8);
T.area(5);
C.area(8);
}
}
output :
Name : SRAVYA PARIDALA
Enrollment No. :A70405221162
Aim : Constructor
Program :
package com.company;
class phone {
phone() {
System.out.println("phone is electronic device");
}
public void smartphone() {
System.out.println("we can play game on smartphone");
}
}
public class experiment6 {
public static void main(String[] args) {
phone Ph = new phone();
Ph.smartphone();
}
}
Output :
Name : SRAVYA PARIDALA
Enrollment No. :A70405221162
Aim : Method Overloading
Program :
package com.company;
class maths{
int sum(int a, int b){
return a+b;
}
double sum(int x, double y){
return x +y;
}
double sum (double x, double y){
return x + y;
}
}
public class experiment4 {
public static void main(String[] args) {
int a;
double b,c;
maths M1 = new maths();
a = M1.sum(2,3);
b = M1.sum(3,5.8);
c = M1.sum(5.7,3.4);
System.out.println("The sum is "+ a);
System.out.println("The sum is "+ b);
System.out.println("The sum is "+ c);
}
}
output :
Name : SRAVYA PARIDALA
Enrollment No. :A70405221162
Aim : Method Overriding
Program :
class A {
public void maths(int a, int b){
System.out.println("sum of two numbers is " + (a +
b));
}
public void methode(){
System.out.println("this is method");
}
}
class B extends A{
public void maths(int a, int b){
System.out.println("multiplication of two numbers is "
+ (a*b));
}
public void methode(){
System.out.println("this is override methode");
}
}
public class experiment_5 {
public static void main(String[] args) {
A a = new A();
a.maths(4,6);
a.methode();
B b = new B();
b.maths(5,6);
b.methode();
}
}
Output:
Name : SRAVYA PARIDALA
Enrollment No. :A70405221162
Aim : Implementation of this and super keyword
Program :
class numbers{
int a,b;
public int multiplication(){
return a*b;
}
numbers(int x, int y){
this.a=x;
this.b=y;
}
}
class divide extends numbers{
divide (int c,int d){
super(c,d);
System.out.println("division of two numbers is "+
(c/d));
}
}
public class experiment_7 {
public static void main(String[] args) {
divide D = new divide(9,3);
System.out.println("multiplication of two numbers is "
+ D.multiplication());
}
}
Output :
Name : Sravya Paridala
Enrollment no. : A70405221162
Batch : B3
Aim :
Class A - Write a program to find that digit is divisible
by 5
Class B - Write a program to find whether the given
integer is odd or even
Program:
class A{
int x;
public void div(){
this.x=17;
//check number is devide by 5 or not
if (this.x %5 ==0){
System.out.println("Number is divisible by 5");
else {
System.out.println("Number is not divisible
by 5");
}
class B extends A{
public void oddeven(){
this.x=49;
//check number is even or odd
if(this.x%2==0){
System.out.println("The Number is even");
}
else {
System.out.println("The Number is odd");
}
}
}
public class exp2{
public static void main(String args[]) {
A Cls1 = new A();
Cls1.div();
B Cls2 = new B();
Cls2.oddeven();
}
}
Output:
Cls1.div(); B Cls2 = new B(); Cls2.oddeven(); } }
Outpute: