Lesson 25 of 34

Classes आणि Objects

10 min 30 XP

Java object-oriented आहे. Class म्हणजे fields (data) आणि methods (कृती) असलेला आराखडा (blueprint). त्यापासून new ने objects तयार करतो, आणि प्रत्येक object च्या स्वतःच्या values असतात.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

एका file मध्ये फक्त एकच public class असू शकतो. तुमचे इतर classes Main च्या वर public शब्दाशिवाय लिहा.

Challenge

+30 XP

length आणि width fields तसेच area() आणि perimeter() methods असलेला class Rectangle लिहा. main() मध्ये length आणि width वाचा आणि print करा: Input: 5 3 Output: Area: 15 Perimeter: 16

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.