Write a class called Person.java that has instance variables matric number, name, date of birth, and gender. Use appropriate data types for these instance variables. Include constructor and set and get methods for all instance variables.

public class Q1L6{

   class Person {
   	    String name;
   	    int DOB;
   	    int MatricNum;
   	    char gender;
   }

   class printingPerson{
   public static void main(String[] args) {
	 Student printingPerson = new Student();
		  System.out.println("Name: \t" + printingPerson.name);
		  System.out.println("Date of Birth:\t" + printingPerson.DOB);
		  System.out.println("Matric Number:\t" + printingPerson.MatricNum);
		  System.out.println("Gender:\t " + printingPerson.gender);
	}//End Main Method
}



	public givingPerson(String name,int DOB,int MatricNum,char gender ) {
		printingPerson.name = name;
		printingPerson.DOB = DOB;
		printingPerson.MatricNum = MatricNum;
		printingPerson.gender = gender;
		}

			//NAME
		 public name getName() {
			return name;
		}

			//DOB
		public DOB getDOB() {
			return DOB;
		}

		  	//MATRIC NUMBER
		public MatricNum getMatricNum() {
		  	return MatricNum;
		}

		  	//GENDER
		public gender getgender() {
		  	return gender;
		}


}

dude you need to go back to the drawing board. You do not yet understand the concept of Object Orientation

Ok I've worked with what you had and made it work after a while of thought but if I gave it to you (the solution), you wouldn't learn from your mistakes, so instead check out these sites: http://java.sun.com/docs/books/tutorial/java/concepts/class.html Also have a look at this site, the initial part and the solution, you have made a similar mistake. http://www.linuxquestions.org/questions/programming-9/java-non-static-variable-this-cannot-be-referenced-from-a-static-context-449245/ If you have any other problems or want me to look at your next attempt just ask ;).

This article has been dead for over six months. Start a new discussion instead.