Define a Simple Class
This program defines a simple class with attributes.
Problem Statement
Write a Java program to define a class Student with attributes name and age, and print them.
Source Code
| 1 | class Student { |
| 2 | String name; |
| 3 | int age; |
| 4 | } |
| 5 | public class ClassDefinition { |
| 6 | public static void main(String[] args) { |
| 7 | System.out.println("Eduinq Class Definition"); |
| 8 | Student s=new Student(); |
| 9 | s.name="Arun"; |
| 10 | s.age=20; |
| 11 | System.out.println("Name: "+s.name+", Age: "+s.age); |
| 12 | } |
| 13 | } |
Program Output
Eduinq Class Definition Name: Arun, Age: 20
Explanation
Class Student defined with attributes. - Object created and values assigned. - Together demonstrates basic class definition. Conclusion: Shows how to define and use a simple class.