Java 233

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Roll no--233

Practical 1
1.A.(a) Program to demonstrate use of constructor overloading.

Code:

class St

public St ()

System.out.println("this is default consructor");

public St(int a,int b)

System.out.println(a+b);

class Pr48

public static void main(String args [])

St s1=new St();

St s2 = new St(27,11);

}
Roll no--233

Output:

1.A(b) Aim- Write a java code on Copy constructor

Code--

package copyex;

import java.util.Scanner;

public class Circle {

public float r,area;

Circle()

Scanner sc=new Scanner (System.in);

System.out.println("Enter the Value:");

r=sc.nextFloat();

Circle(Circle x)

r=x.r;
Roll no--233

void calculate()

area=3.14f*r*r;

void display()

System.out.println("area="+area);

package copyex;

public class copyex{

public static void main(String[] args) {

Circle c=new Circle();

c.calculate();

c.display();

Circle c1=new Circle(c);

c1.calculate();

c1.display();

}
}
Roll no--233

OUTPUT-

1(b) Aim— program to demonstrate use of method overloading.

Code:

package javaapplication13;

class JavaApplication13 {

public void add(int num1,int num2)

System.out.println(num1+num2);

public void add(float num1,float num2)

System.out.println(num1+num2);

public void add(int num1)

System.out.println(num1);

}
Roll no--233

public class etr

public static void main(String args[])

JavaApplication13 s1 = new JavaApplication13();

s1.add(27,56);

s1.add(5.f,6.5f);

s1.add(88);

Output:
Roll no--233

1(c) Aim— Write program to create a class and implements the concept
of static method .

Code--

package staticmethod;

class Employee {

int empid;

String name;

static String company="Sincetele";

static void change() {

company = "sall";

Employee (int e,String n){

empid= e;

name= n;

void display(){

System.out.println(empid + "" + name + "" + company);

public class Staticmethod {


Roll no--233

public static void main(String[] args) {

Employee.change();

Employee e1=new Employee(1,"Hema");

Employee e2=new Employee(2,"Akku");

e1.display();

e2.display();

OUTPUT--
Roll no--233

Practical 2

2.(A) Aim—Write a program to implement the concept of


Inheritance.

Code--
class A

void show() {

System.out.println("Base class");

class B extends A

@Override

void show()

System.out.println("Derieved Class");

class Main

public static void main(String[] args) {

B s=new B();
Roll no--233

s.show();

Output--

2(B). Aim-- Write a program to implement the concept of Abstract classes


and Methods.

Code--

package abstractclass;

import java.util.*;

abstract class base{

protected float r,vol;

public void read(float x)

r=x;

public abstract void calculate();


Roll no--233

public void display(){

System.out.println("The volume is:"+vol);

class Sphere extends base{

public void calculate(){

vol=3.14f*r*r*r*4/3;

public class Abstractclass {

public static void main(String[] args) {

float x;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the radius");

x = sc.nextFloat();

Sphere s = new Sphere();

s.read(x);

s.calculate();

System.out.println("Sphere:");

s.display();
Roll no--233

Output--

2(C).Aim-- Write a program to implement the concept of interfaces.

Code--

package interfaces;

interface area{

void show (int s,int t);

class Rect implements area{

public void show(int s,int t){

System.out.println("Area of rectangle:");

System.out.println(s*t);

}
Roll no--233

class Circle implements area{

public void show(int s,int t){

System.out.println("Area of circle:");

System.out.println(3.14f*s*s);

public class Interfaces {

public static void main(String[] args) {

Rect r = new Rect();

r.show(3,4);

Circle c = new Circle();

c.show(3,4);

Output--

You might also like