Thursday, 13 August 2015

Java Tutorial : What is a Class(Girl/boy)?

Master Java with Us!

Enjoying this guide? Subscribe to Ram N Java for straightforward, beginner-friendly programming tutorials!

Subscribe on YouTube

What is a Class in Java? Real-World Analogy Explained

In Java, everything revolves around Classes and Objects. Anything we want to represent in a Java program must be encapsulated within a class. If you are learning Object-Oriented Programming (OOP) for the first time, thinking of a class as a blueprint or real-world concept makes it extremely easy to understand.

1. What is a Class? (The Blueprint)

A class is a blueprint or template from which individual objects are created. It defines what state (variables) and behavior (methods) the resulting objects will have.

  • Using a class Girl, we can create multiple individual girl objects.
  • Using a class Boy, we can create multiple individual boy objects.
  • Objects interact and communicate with each other by calling methods.

2. Syntax of a Java Class

A class is declared using the class keyword followed by the class name. Inside the curly braces, you declare its variables and methods:

public class Boy {
    // Variables (Attributes / State)
    String name;
    int age;

    // Methods (Behaviors / Actions)
    public void speak() {
        System.out.println("Hello, I am " + name);
    }
}

3. Key Parts of a Class Declaration

  1. Access Modifiers: Keywords like public, default, or private determine the visibility of the class.
  2. Class Keyword: The keyword class is used to define a class type.
  3. Class Name: By Java naming conventions, class names begin with a capital letter (PascalCase).
  4. Inheritance (extends): If a class inherits from a parent or superclass, you use the extends keyword.

Watch More Java Tutorials from Ram N Java


Click here to watch in Youtube :
https://www.youtube.com/watch?v=2WD3y7V3lGY&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : What is a Class(Girl/boy)? 
Java Tutorial : What is a Class(Girl/boy)? 
See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Tutorials