//Note: Java Object Oriented Programming Simple Examples
//[1]
class Bank{
private int accno;
private String name;
private float balance;
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust1{
public static void main(String arg[]){
Bank c1=new Bank();
c1.setData(1000,"sun",500.00);
c1.display();
Bank c2=new Bank();
c2.setData(1001,"sen",500.00f);
c2.display();
}
}
//[2]
class Bank{
private int accno;
private String name;
private float balance;
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust2{
public static void main(String arg[]){
Bank c1=new Bank();
c1.setData(1000,"sun",500.00f);
//c1.display();
Bank c2;
c2=c1;
c2.setData(1001,"sen",600.00f);
c1.display();
}
}
//[3]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
return 0;
}
Bank(int i,String n,float b){
accno=i;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust3{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.display();
Bank c2=new Bank(1001,"sen",600.0f);//calling three argument constructor
c2.display();
}
}
//[4]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
}
Bank(int i,String n,float b){
accno=i;
name=n;
balance=b;
}
public void interest(){
float i=balance*10.0f/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void interest(int ip){
float i=balance*ip/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust4{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.interest();//calls no argument interest method
c1.display();
Bank c2=new Bank(1001,"sen",600.0f);//calling three argument constructor
c2.interest(8);//calls one argument interest method
c2.display();
}
}
//[5]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
}
Bank(int accno,String name,float balance){
this.accno=accno;
this.name=name;
this.balance=balance;
}
public void interest(){
float i=balance*10.0f/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void interest(int ip){
float i=balance*ip/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust5{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.interest();//calls no argument interest method
c1.display();
}
}
//[6]
class Bank{
private int accno;
private String name;
private float balance;
public static int cust=0;
Bank(){
System.out.println("object created now");
cust++;
}
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust6{
public static void main(String arg[]){
Bank c1=new Bank();
Bank c2=new Bank();
Bank c3=new Bank();
Bank c4=new Bank();
Bank c5=new Bank();
System.out.println("no of customers in the bank"+Bank.cust);
}
}
//[1]
class Bank{
private int accno;
private String name;
private float balance;
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust1{
public static void main(String arg[]){
Bank c1=new Bank();
c1.setData(1000,"sun",500.00);
c1.display();
Bank c2=new Bank();
c2.setData(1001,"sen",500.00f);
c2.display();
}
}
//[2]
class Bank{
private int accno;
private String name;
private float balance;
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust2{
public static void main(String arg[]){
Bank c1=new Bank();
c1.setData(1000,"sun",500.00f);
//c1.display();
Bank c2;
c2=c1;
c2.setData(1001,"sen",600.00f);
c1.display();
}
}
//[3]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
return 0;
}
Bank(int i,String n,float b){
accno=i;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust3{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.display();
Bank c2=new Bank(1001,"sen",600.0f);//calling three argument constructor
c2.display();
}
}
//[4]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
}
Bank(int i,String n,float b){
accno=i;
name=n;
balance=b;
}
public void interest(){
float i=balance*10.0f/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void interest(int ip){
float i=balance*ip/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust4{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.interest();//calls no argument interest method
c1.display();
Bank c2=new Bank(1001,"sen",600.0f);//calling three argument constructor
c2.interest(8);//calls one argument interest method
c2.display();
}
}
//[5]
class Bank{
private int accno;
private String name;
private float balance;
Bank(){
accno=1000;
name="sun";
balance=500.0f;
}
Bank(int accno,String name,float balance){
this.accno=accno;
this.name=name;
this.balance=balance;
}
public void interest(){
float i=balance*10.0f/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void interest(int ip){
float i=balance*ip/100;
System.out.println("interest="+i);
balance =balance+i;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust5{
public static void main(String arg[]){
Bank c1=new Bank();//calling no argument constructor
c1.interest();//calls no argument interest method
c1.display();
}
}
//[6]
class Bank{
private int accno;
private String name;
private float balance;
public static int cust=0;
Bank(){
System.out.println("object created now");
cust++;
}
public void setData(int a,String n,float b){
accno=a;
name=n;
balance=b;
}
public void display(){
System.out.println("Accno"+accno);
System.out.println("Name"+name);
System.out.println("Balance"+balance);
}
}
class Bankcust6{
public static void main(String arg[]){
Bank c1=new Bank();
Bank c2=new Bank();
Bank c3=new Bank();
Bank c4=new Bank();
Bank c5=new Bank();
System.out.println("no of customers in the bank"+Bank.cust);
}
}
No comments:
Post a Comment