Sat Jan 31, 2009 12:18 am
public class Main {
public static void main(String[] args) {
BMW_H5 car1=new BMW_H5("Owner1");
BMW_H5 car2=new BMW_H5("Owner2");
System.out.println("Car 1 owner "+car1.getOwnername());
System.out.println("Car 1 : salary "+car1.getSalary());
System.out.println("Car 2 owner "+car2.getOwnername());
System.out.println("Car 2 : salary "+car2.getSalary());
BMW_H5.setSalary(6999.0f);
System.out.println("Car 1 owner "+car1.getOwnername());
System.out.println("Car 1 : salary "+car1.getSalary());
System.out.println("Car 2 owner "+car2.getOwnername());
System.out.println("Car 2 : salary "+car2.getSalary());
}
}
class BMW_H5
{
private static float salary=5000.0f;
private String ownername;
public BMW_H5(String ownername)
{
this.ownername=ownername;
}
public static float getSalary() {
return salary;
}
public static void setSalary(float salary) {
BMW_H5.salary = salary;
}
public String getOwnername() {
return ownername;
}
public void setOwnername(String ownername) {
this.ownername = ownername;
}
}
Car 1 owner Owner1
Car 1 : salary 5000.0
Car 2 owner Owner2
Car 2 : salary 5000.0
Car 1 owner Xonwer1
Car 1 : salary 6999.0
Car 2 owner Xonwer2
Car 2 : salary 6999.0
public class Main {
public String myname="Tom";
public static void main(String[] args) {
System.out.println("myname = "+myname);
}
}
public class Main {
public static int x=0;
static
{
x++;
System.out.println("static block x="+x);
}
public static void main(String[] args) {
Main obj=new Main();
System.out.println("main function x="+x);
}
}
static block x=1
main function x=1
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.