Java All Codes
Java All Codes
Branch: Comp b
Roll No: 1021269
Input:
import java.util.Scanner;
class main
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter Name,Age and Salary of Employee:");
String N=obj.nextLine();
int A=obj.nextInt();
double S=obj.nextDouble();
System.out.println("Employee Name:"+N);
System.out.println("Employee Age:"+A);
System.out.println("Employee Salary:"+S);
}
}
Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement Class and Objects.
import java.util.*;
class student
{
String Name;
int rollNo;
void printName(String Name, int rollNo)
{
System.out.println("Student's Name is :"+Name);
System.out.println("Roll No : " +rollNo);
}
}
class teacher
{
String tName;
void printTName(String tName)
{
System.out.println("Teacher's Name is :"+ tName);
}
}
class stud
{
public static void main(String args[])
{
student s1 = new student();
s1.printName("Pranav Chaudhari", 1021167);
teacher t1 = new teacher();
t1.printTName("Bhakti Mam");
}
}
Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement Method Overloading
import java.util.*;
class methodoverloading
{
static int add(int a,int b)
{
return a+b;
}
static int add(int a,int b,int c)
{
return a+b+c;
}
}
class overloading
{
public static void main(String[] args)
{
System.out.println(methodoverloading.add(23,25));
System.out.println(methodoverloading.add(20,10,20));
}
}
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement the Concept of Inheritance.
import java.util.*;
class parent
{
public void printa()
{
System.out.println("You are in Parent Class..!!");
}
}
class child extends parent
{
public void printb()
{
System.out.println("So now,You are in Child Class..!!");
}
}
class inheritance
{
public static void main(String[]args)
{
child c1=new child();
c1.printa();
c1.printb();
}
}
Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement String Functions.
public class strlen
{
public static void main(String args[])
{
String s1="Pranav Chaudhari";
System.out.println("String length is: "+s1);
System.out.println("String length is: "+s1.length());
}
}
Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
Output: