It is an open-source object-oriented programming language. Example:- //Emp.java package com.comp; public class Emp { //Define some pro...
It is an open-source object-oriented programming language.
Example:-
//Emp.java
package com.comp;
public class Emp {
//Define some properties
private int id;
public int getId() {
return id;
}
public String getName() {
return Name;
}
public String getAdds() {
return Adds;
}
private String Name;
private String Adds;
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
Name = name;
}
public void setAdds(String adds) {
Adds = adds;
}
}
Main Class
package com.comp;
public class Master {
public static void main(String[] args) {
// TODO Auto-generated method stub
Emp emp = new Emp();
emp.setId(1);
emp.setAdds("Bangalore");
emp.setName("ABC");
System.out.println(emp.getId() + "," + emp.getName() + emp.getAdds());
}
}
------------Example 2--------------------
package com.comp;
public class Emp {
//Define some properties
public Emp(int id, String name, String adds) {
Id=id;
Name=name;
Adds=adds;
}
private int Id;
private String Name;
private String Adds;
@Override
public String toString() {
return "Emp [Id=" + Id + ", Name=" + Name + ", Adds=" + Adds + "]";
}
}
package com.comp;
public class Master {
public static void main(String[] args) {
// TODO Auto-generated method stub
Emp emp = new Emp(1,"Raman","Bangalore");
System.out.println(emp);
}
}
----Unit Test example
public class Master {
public static void main(String[] args) {
int num1,num2;
num1=2;
num2=8;
int result= sum(num1,num2);
System.out.println(TestResult(num1,num2,result));
}
public static int sum(int a,int b) {
return a+b;
}
public static String TestResult(int a, int b, int result)
{
String returnresult;
if(result==a+b)
returnresult="Passed";
else
returnresult="Failed";
return returnresult;
}
}
COMMENTS