main class:-
package examdetail;
/**
*
*/
public class Examdetail {
public static void main(String[] args) {
studentresult s=new studentresult();
String ss=s.full_name = "ahmed abdulkarim";
System.out.println(ss);
System.out.println(s.examname("vb"));
System.out.println(s.getgrade(13));
}
}
sub class:-
package examdetail;
/**
*
*/
public class studentresult {
String full_name;
String exam_name;
String exam_grade;
studentresult(){
full_name="no name";
exam_name="un known";
}
String fullname(String name)
{
full_name=name;
return full_name;
}
String examname(String ename)
{
if(ename.equals("vb"))
exam_name="visualbasic";
else if(ename.equals("j"))
exam_name="java";
else if(ename.equals("p"))
exam_name="php";
return exam_name;
}
private String examgrade(int score)
{
if(score>=0&&score<=20)
exam_grade="f";
if(score>=21&&score<=40)
exam_grade="E";
return "the grad is :"+exam_grade;
}
String getgrade(int score) // to accses private function
{
exam_grade=this.examgrade(score);
return exam_grade;
}
}
0 التعليقات:
إرسال تعليق