Home / learning / Java / What is Class In Java Programming Language With Example

What is Class In Java Programming Language With Example

Publisher:
License:
Filesize:
Price:
Date added: July 9, 2013
Downloads:

Class and Objects are the one of the important concepts of the object oriented programming language. And java is incomplete without classes every thing we discussed in java is purely depends on class and object oriented.

Here in this article we are going to learn how to use class with example.

Definition:

A class is the template or blueprint from which objects are actually created. The class is created with the keyword followed by the name of the class. All objects are the instances of class.

Now let us consider an example

Access Specifiers of the classes

  • public
  • protected
  • default (not specified)
  • private

If the class has access specifier as public then it can be accessed from anywhere..

And if it is default it is accessed from the same package only

  Access Specifiers   Same Class   Same Package   Subclass   Other packages
  public Y Y Y Y
  protected Y Y Y N
  no access modifier Y Y N N
  private Y N N N

Y for Yes

N for NO

Points To Remember About The Class

  • A program is made up of one or more classes

  • Name of the file should coincide with the name of the class if that class is declared as public

  • Public indicates it is visible from any point of the program

  • Static is to call the method without creating an instance of the class

  • Void indicates, it does not return anything.

  • string args[] is to take the data from command prompt.

  • Java file should not contain more than one public class.

  • The data or variables defined within the class are called instance variables

  • Functions defined within a class are called methods.

  • The class declaration and the implementation of the method   should be within the same class

Recommended Articles on java

If you had any doubts or comments regarding this article let us know through comments.

About Amar

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 5 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top