Java

Java OOPS Classes and Objects

In this tutorials will  teach you what is the Classes and Objects step by step. This is an important for developing a java projects.  there are many students who struggling with this area. so that I bring this article for all to clear the doubts.

Classes

Classes are just a blue print or template.

Example

public class Product 
{
    //Attributes
   public String model;      
   public String brand;
   public double price;
   public String serial;
   public boolean tested;

  //Methods    
   public void sell()
    {
        System.out.println("Sales");
    }
    
   public void repair()
    {
         System.out.println("repair");
    }
    
    public void test()
    {
         System.out.println("test");
    }
 
}

Objects

Object are including methods and attributes.  i already created the class above.inside  the class consist of attributes and methods.  i have created the another class which name is test.java. By creating a object using the name of the class product.

//Object Creation
Product p1 = new Product();

Create the objects and assign the attributes and methods. i explained below code.

public class test 
{   
    public static void main(String args[])
    {
         //Object Creation
        Product p1 = new Product();
        p1.brand = "Toyato";
        p1.model = "BMW";
        p1.price = 500000;
        p1.tested = true;
        p1.sell();
        
        Product p2 = new Product();
        p2.brand = "abc";
        p2.model = "BBB";
        p2.price = 600000;
        p2.tested = true;
        p2.sell();
        
        Product p3 = new Product();
        p3.brand = "cvb";
        p3.model = "ert";
        p3.price = 700000;
        p3.tested = false;
        p3.sell();
        
        
        System.out.println("Brand is " +  p1.brand);
        System.out.println("model is " +  p1.model);
        System.out.println("model is " +  p2.model);
        System.out.println("model is " +  p3.model);
        p1.sell();
        
    }

i have attached the video link below. which will do this tutorials step by step.

 

 

admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

4 days ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

6 days ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

7 days ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

2 weeks ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

3 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

4 weeks ago