
It would be like a class Good if not used on any person, or animal or thing, then Good will just remain a feeling. So I should say Good boy, or good girl. For that I will have to use that abstract class in some concrete class. So now I declare another normal class ‘Boy’ and use ‘Good’ abstract class. Once when I use Good class in Boy subclass, I can use all the methods written in Good class in Boy class to give it a proper implementation. For using both these classes and the methods written in both the classes, I have created another class called StudentConduct.
public abstract class Good {
private String quality;
public abstract void getDegreeOfGoodness(int goodnessMarks);
public String getQuality()
{
quality = "Good";
return quality;
}
}
public class Boy extends Good {
int behaviorMarks=0;
String degree="";
public void getDegreeOfGoodness(int behaviorMarks)
{
if(behaviorMarks >10)
degree="Very Very";
else if((behaviorMarks <> 7))
degree = "Very";
else if((behaviorMarks <> 4))
degree = "Ok";
else if(behaviorMarks < 4)
degree = "Not";
System.out.println(degree+" "+getQuality());
}
}
public class StudentConduct extends Boy {
public void getStudentConduct()
{
Boy b1 = new Boy();
b1.getDegreeOfGoodness(5);
}
public static void main(String args[])
{
StudentConduct sc = new StudentConduct();
sc.getStudentConduct();
}
}
The above abstract class Good, has two methods, one is abstract and another one, non-abstract, returning the string quality. The method is “getQuality()”, that has a string ‘quality’. In another class, the method is directly called, without changing the string ‘quality’ there by making sure it is untouched. Also the string is declared as private, to protect it from getting changed in any other place. Once this string is declared as private, its value cannot be changed. This phenomenon is called encapsulation or hiding and protecting your data from misuse.
Thanks for sharing the informative post. java training
ReplyDeletejava online training
A good blog always contains new and exciting information and as I read it I felt that this blog really has all of these qualities that make a blog. We are also providing the best services click on below links to visit our website.
ReplyDeleteOracle Fusion HCM Training
Workday Training
Okta Training
Palo Alto Training
Adobe Analytics Training