Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

adplus-dvertising
Class Declaration in Java
Previous Home Next

class is a collection of similar type of object .A class is a blue print for the object, that blueprint describes the each object behaviors and state variable.

A class represent ADT(Abstract Data Type). It acts like a template using which we can create multiple objects. A class Declaration only create a template, it does not create an actual object . A class creates a new data type that can be used to create object. That a class creates a logical framework that defines the relationship between its member. when we declare an object of a class, we are creating an instance of that class. thus a class is a logical construct. An object has physically reality.

Declaration of class:

Access modifiers( public)( abstract | final) class class_name extends
	MySuperClass implements YourInterface
{
	// behaviors and state variables are declared between the { and } characters
}
  1. Modifiers declare whether the class is public, abstract, or final.
  2. The class declaration must contain the class keyword and the class name of the class that you are defining.
  3. The class name, with the initial letter capitalized by convention (Title case).
  4. The name of the superclass, if any, preceded by the keyword extends. A class can only extend one subclass.
  5. The name of the interfaces implemented by the class, if any, preceded by the keyword implements.
  6. A class can implement more than one interface.
  7. The class body, surrounded by braces, {}.

Example :

import java.util.Scanner;
    class B
    {
		private int x;
		private float y;
        void getData()//for user input
        {
             Scanner sc;
             sc=new Scanner(System.in);
             System.out.print("Enter Value Of x :");
             x=sc.nextInt();
             System.out.print("Enter value of y :");
             y=sc.nextFloat();
         } 
         void setdata(int x1,float y1)//for testing purpose
         {
                    x=x1;
                    y=y1;
         }
         void display()
         {
                            System.out.println(x+","+y);
         }
    }
    class BTest
    {
         public static void main(String args[])
		{ 
              B a1,a2;
              a1=new B();
              a2=new B();
              //a1.x=5 ;//error
              //a1.getdata();
              //a2.gatdata();
              a1.setdata(10,10.5f);
              a2.setdata(2,5.4f);
              a1.display();
              a2.display();
         }
  }

output :

10,10.5
 2,5.4
Previous Home Next