2.2. Declaring Members: Fields and Methods

Let’s look at an example Class and see how to declare its fields and methods.

			package javatutorial;

			/**
			 * Example class, showing declaration of fields and methods in a class
			 * 
			 * @author f5java.com
			 */
			public class Student {
				private String name;
				private String course;
				private String grade;
				
				Student (String name, String course, String grade){
					this.name = name;
					this.course = course;
					this.grade = grade;		
				}
				
				/**
				 * Displays student details
				 */
				public void displayStudentDetails(){
					System.out.println("Name: " + name);
					System.out.println("Course: " + course);
					System.out.println("Greade: " + grade);
				}

			}