AIM: Create a class to find out whether the given year is leap year or not. (Use inheritance for this program)
LeapYearInheritance.java
Output
Happy Coding :)
LeapYearInheritance.java
import java.util.Scanner; class FindLeapLogic { int year; boolean leap=false; void logic(int x) { year=x; if(year%4==0) { if(year%100==0) { if(year%400==0) { leap=true; } else { leap=false; } } else { leap=true; } } else { leap=false; } } } class DisplayYear extends FindLeapLogic { void display() { if(leap) { System.out.println(year + " is a leap year (@_@)"); } else { System.out.println(year+" is not a leap year [@_@]"); } } } class LeapYearInheritance { public static void main(String arg[]) { DisplayYear d1=new DisplayYear(); Scanner sc=new Scanner(System.in); System.out.print("Enter Year: "); int y=sc.nextInt(); d1.logic(y); d1.display(); } }
Output
Leap year or not using inheritance in java by practical server |
Happy Coding :)
1 Comments
that's gazab bro are you gtu student and a toppper , what eever your this blogspot is too much help full from completing my java and dwpd lab manul fastly
ReplyDeletePost a Comment