www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons Java Classes Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Classes and Objects are the heart and sould of the OOP (Object Oriented Programming) and without them OOP cannot exist. In this lesson we will start our discussion on Java classes. As C++ programmers, you will glad to know that Java classes are almost the same as C++ classes. Like C++ classes, Java classes contain fields also called instance variables or properties of an object and methods. A field is like a C++ data member, and a method is like a C++ member function.

A Simple Example Class
In the following example, a List is defined to be an ordered collection of items of any type:
class List {    
  // fields        
  private Object [ ] items;    	// store the items in an array
  private int  numItems; 	// the current # of items in the list 
		
  //methods        

  // constructor function        
  public List() {            
  items = new Object[10];	    
  numItems = 0;        
  }		
		
  // AddToEnd: add a given item to the end of the list	
  public void AddToEnd(Object ob){ 
		 
  }
}
In Java, all classes (built-in or user-defined) are (implicitly) subclasses of the class Object. Using an array of Object in the List class allows any kind of Object (an instance of any class) to be stored in the list. However, primitive types (int, char, etc) cannot be stored in the list as they are not inherited from Object.
Next >>> Lesson No. 7: The Constructor Function







Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.