FANDOM


Class

Classes are very useful, even their creation icons!


Introduction Edit

In the java wiki, when you write an article about a specific class you name it like: Class packageName.className

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create objects. This blueprint includes attributes and methods that the created objects all share.

Usually, a class represents a person, place, or thing - it is an abstraction of a concept within a computer program. Fundamentally, it encapsulates the state and behavior of that which it conceptually represents. It encapsulates state through data placeholders called member variables; it encapsulates behavior through reusable code called methods.

More technically, a class is a cohesive package that consists of a particular kind of metadata. It describes the rules by which objects behave; these objects are referred to as instances of that class. A class has both an interface and a structure. The interface describes how the class and its instances can be interacted with via methods, while the structure describes how the data is partitioned into attributes within an instance. A class may also have a representation (metaobject) at runtime, which provides runtime support for manipulating the class-related metadata. In object-oriented design, a class is the most specific type of an object in relation to a specific layer.

Programming languages that support classes all subtly differ in their support for various class-related features. Most support various forms of class inheritance. Many languages also support features providing encapsulation, such as access specifiers.

Classes In JavaEdit

In java, there are different types of classes. The regular class is the most used as it is designed to create an object for normal use. It typically includes constuctor(s) for it initilization, get and set methods for private instance variables and methods specific to the perticular object. The second is an enum class which is for declaring enums with a constructor and empty methods. The third type is an interface class which is used as a template for building a class, and an abstract class which is simmilar to an interface but with some of the methods provided. The class type must be provided for the compiler (ex: public enum cards)

Information Hiding Edit

Many languages support the concept of information hiding and encapsulation, typically with access specifiers for class members. Access specifiers specify constraints on who can access which class members. Some access specifiers may also control how classes inherit such constraints. Their primary purpose is to separate the interface of a class with its implementation.

A common set of access specifiers that many object-oriented languages support is:

  • Private (or class-private) restricts the access to the class itself. Only methods that are part of the same class can access private members.
  • Protected (or class-protected) allows the class itself and all its subclasses to access the member.
  • Public means that any code can access the member by its name.

Example of a Class in Action Edit


// This is a Java class, it automatically extends the class Object

public class HelloWorld {

 public static void main (String[] args) {
  
   System.out.println ("Hello World!");
 
   }

}


See Also Edit

Java

Data Structures

Learning Object Oriented Programming with Java

JAVA Cores

Links Edit

Wikipedia definition

Smallwikipedialogo.png This page uses content from Wikipedia. The original article was at Class (computer science). The list of authors can be seen in the page history. As with Java Wiki, the text of Wikipedia is available under the GNU Free Documentation License.



Java Rules!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.