import java.util.Scanner; class Rectangle4{ int l, b; void getData(){ Scanner in = new Scanner(System.in); System.out.print("Enter length : "); l=in.nextInt(); System.out.print("Enter breadth : "); b=in.nextInt(); } void displayArea(){ int a; a = l*b; System.out.println("Area = "+a); } public static void main(String args[]){ Rectangle4 obj = new Rectangle4(); obj.getData(); obj.displayArea(); } }
Write a Java program to create Rectangle class with data member length and breadth. Include methods getData() and displayArea() in the class. Finally create an object of Rectangle class and display its area.
java, java programming, java program to create methods, java program methods example, java programming example to create methods and class,
Post a Comment