Basic Java Lab File
Basic Java Lab File
Basic Java Lab File
if(x%2==0)
{
System.out.println("You press even number.");
}
else
{
System.out.println("You press odd number.");
}
}
}
Output:
Experiment No. 03
// WAP to create class person with variables name, age and salary. Create a person object. Set
and display its instance variables.
import java.util.*;
class person
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name:");
String name = sc.nextLine();
System.out.println("Name:"+ name);
System.out.println("Age:"+ age);
System.out.println("Salary:"+ salary);
}
}
Output:
Experiment No. 04
class bank
{
int balance;
bank()
{
balance=10000;
}
bank(int balance)
{
this.balance=balance;
}
public void display()
{
System.out.println("Initial Balance:" + balance);
}
public static void main(String args[])
{
bank b = new bank();
bank b1 = new bank(50000);
b.display();
b1.display();
}
}
Output:
Experiment No. 05
class student
{
String branch;
student()
{
branch = "CSE";
}
student(student s1)
{
branch = s1.branch;
}
public void display()
{
System.out.println("Branch: "+branch);
}
public static void main(String args[])
{
student s = new student();
student s1 = new student(); //passing object as parameter.
s.display();
s1.display();
}
}
Output: