Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,

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,



 

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();  
	}
}


Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget