0% found this document useful (0 votes)
22 views4 pages

JAVA7

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

JAVA7

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program for Constructor overloading:-

import java.util.*;

class Student

String name;

int roll;

String add;

void Student()

System.out.println("Student Details:");

void Student(String n, int r,String ad)

name = n;

roll = r;

add = ad;

System.out.println("Student name: " +name);

System.out.println("Student roll_no: " +roll);

System.out.println("Student Address: " +add);

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

System.out.println("Enter Student name: ");

String name = sc.nextLine();

System.out.println("Enter Student roll no: ");

int roll = sc.nextInt();

System.out.println("Enter Student Address: ");

String add=sc.nextLine();

Student s =new Student();

Student s1 = new Student(name, roll, add);

}
Output:-
Program for Method overloading:-
import java.util.*;

class metover

//By changing number of arguments

void add(int a, int b)

System.out.println("Sum of 2 ints "+a+" & "+b+" : "+(a+b));

void add(int a, int b, int c)

System.out.println("Sum of 3 ints "+a+" & "+b+" & "+c+" : "+(a+b+c));

//By changing datatype of arguments

void mul(int a, int b, int c)

System.out.println("Product of 3 ints "+a+" & "+b+" & "+c+" : "+(a*b*c));

void mul(float p, float q, float r)

System.out.println("Product of 3 floats "+p+" & "+q+" & "+r+" : "+(p*q*r));

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Enter integers a, b & c : ");

int a = sc.nextInt();

int b = sc.nextInt();

int c = sc.nextInt();

System.out.println("Enter floats a, b & c : ");

float p = sc.nextFloat();
float q = sc.nextFloat();

float r = sc.nextFloat();

metover m = new metover();

m.add(a, b);

m.add(a, b, c);

m.mul(a, b, c);

m.mul(p, q, r);

Output:-

You might also like