Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Program One

package oop;

//static method accessing static variable


public class Sample {

static int x = 10;

static void display() {


x++;
System.out.println(" x value is = " + x);
}
}
class SDemo {

public static void main(String args[]) {


System.out.print("Calling static method using Class name:");
Sample.display();
Sample s1 = new Sample();
System.out.print("Calling static method using Object name:");
s1.display();
}
}
Program Three
package oop;

class Sample2 {

void add(int a, int b) {


System.out.println("sum of two=" + (a + b));
}

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


System.out.println("sum of three=" + (a + b + c));
}
}

class OverLoad {

public static void main(String[] args) {


Sample2 s = new Sample2();
s.add(20, 25);
s.add(20, 25, 30);
}
}
Program_Two
package finalexam;

class Employee {

private String name;


private String id;
private String brithdate;
private int salary;
private String allowance;
private int rate;

Employee() // default constructor. No argument list


{
name = "Ahmet";
id = "1234";
salary = 100;
brithdate="10/10/10";

}
public Employee(String n) // non-default constructor
{
name = n;
}
public Employee( String i, String b, int s) // non-default constructor
{
id = i;
salary = s;
brithdate=b;
}

void display() {
System.out.println("\nEmploye Info ");
System.out.println("Name " + name);
System.out.println("ID " + id);
System.out.println("Salary " + salary);
System.out.println("brithdate " + brithdate);
}
}

class ExEmp {

public static void main(String[] args) {


Employee e1 = new Employee();
e1.display();
Employee e4 = new Employee("98745","10/10/10", 400);
e4.display();
}
}

You might also like