File: /home/saiesh/ADS/Assignment No 12/ads12_1.java
//Instance Variable
import java.io.*;
public class ads12_1
{
public String name;
private double salary;
public ads12_1 (String empName)
{
name=empName;
}
public void setSalary(double empSal)
{
salary=empSal;
}
public void printEmp()
{
System.out.println("Name\t: "+name);
System.out.println("Salary\t: "+salary);
}
public static void main(String[] args)
{
ads12_1 empOne=new ads12_1("Saiesh");
empOne.setSalary(10000);
empOne.printEmp();
}
}
/*
saiesh@saiesh :~$ javac ads12_1.java
saiesh@saiesh :~$ java ads12_1
Name
: Saiesh
Salary : 10000.0
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1
....................
File: /home/saiesh/ADS/Assignment No 12/ads12_2.java
Page 1 of 1
//Static Variable
import java.io.*;
public class ads12_2
{
private static double salary;
public static final String DEPARTMENT = "Development";
public static void main(String args[])
{
salary=1000;
System.out.println(DEPARTMENT+" average salary: "+salary);
}
}
/*
saiesh@saiesh :~$ javac ads12_2.java
saiesh@saiesh :~$ java ads12_2
Development average salary: 1000.0
saiesh@saiesh :~$ */
OUTPUT
.................
File: /home/saiesh/ADS/Assignment No 12/ads12_3.java
//Local Variable
public class ads12_3
{
public void pupAge()
{
int age=0;
age=age+7;
System.out.println("Puppy age is: "+age);
}
public static void main(String args[])
{
ads12_3 tes=new ads12_3();
tes.pupAge();
}
}
/*
saiesh@saiesh :~$ javac ads12_3.java
saiesh@saiesh :~$ java ads12_3
Puppy age is: 7
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1
...............
File: /home/saiesh/ADS/Assignment No 12/ads12_4.java
Page 1 of 1
//Global Variable
public class ads12_4
{
public ads12_4()
{
//auto generated constructor
}
public static void main(String[] args)
{
int n1;
n1=10;
if(n1==10)
{
int n2=20;
System.out.println("n1 and n2\t: "+n1+"
}
System.out.println("n1 is\t\t: "+n1);
}
}
/*
saiesh@saiesh :~$ javac ads12_4.java
saiesh@saiesh :~$ java ads12_4
n1 and n2
: 10 20
n1 is
: 10
saiesh@saiesh :~$ */
OUTPUT
"+n2);
//Instance Variable
import java.io.*;
public class ads12_1
{
public String name;
private double salary;
public ads12_1 (String empName)
{
name=empName;
}
public void setSalary(double empSal)
{
salary=empSal;
}
public void printEmp()
{
System.out.println("Name\t: "+name);
System.out.println("Salary\t: "+salary);
}
public static void main(String[] args)
{
ads12_1 empOne=new ads12_1("Saiesh");
empOne.setSalary(10000);
empOne.printEmp();
}
}
/*
saiesh@saiesh :~$ javac ads12_1.java
saiesh@saiesh :~$ java ads12_1
Name
: Saiesh
Salary : 10000.0
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1
....................
File: /home/saiesh/ADS/Assignment No 12/ads12_2.java
Page 1 of 1
//Static Variable
import java.io.*;
public class ads12_2
{
private static double salary;
public static final String DEPARTMENT = "Development";
public static void main(String args[])
{
salary=1000;
System.out.println(DEPARTMENT+" average salary: "+salary);
}
}
/*
saiesh@saiesh :~$ javac ads12_2.java
saiesh@saiesh :~$ java ads12_2
Development average salary: 1000.0
saiesh@saiesh :~$ */
OUTPUT
.................
File: /home/saiesh/ADS/Assignment No 12/ads12_3.java
//Local Variable
public class ads12_3
{
public void pupAge()
{
int age=0;
age=age+7;
System.out.println("Puppy age is: "+age);
}
public static void main(String args[])
{
ads12_3 tes=new ads12_3();
tes.pupAge();
}
}
/*
saiesh@saiesh :~$ javac ads12_3.java
saiesh@saiesh :~$ java ads12_3
Puppy age is: 7
saiesh@saiesh :~$ */
OUTPUT
Page 1 of 1
...............
File: /home/saiesh/ADS/Assignment No 12/ads12_4.java
Page 1 of 1
//Global Variable
public class ads12_4
{
public ads12_4()
{
//auto generated constructor
}
public static void main(String[] args)
{
int n1;
n1=10;
if(n1==10)
{
int n2=20;
System.out.println("n1 and n2\t: "+n1+"
}
System.out.println("n1 is\t\t: "+n1);
}
}
/*
saiesh@saiesh :~$ javac ads12_4.java
saiesh@saiesh :~$ java ads12_4
n1 and n2
: 10 20
n1 is
: 10
saiesh@saiesh :~$ */
OUTPUT
"+n2);
Comments
Post a Comment