Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What is Class in Java?

+20 votes
asked Sep 23, 2024 by Sisay Gebremariam (250 points)

4 Answers

0 votes
answered Sep 24, 2024 by Peter Minarik (101,360 points)

Classes in object-oriented programming are the fundamentals of encapsulation. Classes hold functionality that can be grouped to organize your code logically.

For instance, if you have functionality that helps you maintain employee information (name, address, ID, taxId, etc) and you have functionality that does payroll (create invoice, send invoice, transfer money) you would want to logically separate them into two different classes: Employee and Payroll (with the respective functionality) instead of having a mixture of functions lying around.

Classes are also the "blueprints" of instances when you fill out a "blueprint" with data. Employee is just a class, but when you create a new Employee with exact details, e.g.: johnDoe = Employee("John Doe", "12 Main Street, Dortmund, Germany", "ID1234567890", "TAX123456") then you have an instance. A new instance of the same class filled with different data will be different from the other instances.

Read more here.

+1 vote
answered Oct 11, 2024 by Nikhila Nandyala (410 points)
public class Car{
        String color;
        String model;
        int year;
       
        public  Car(String color, String model,int year){
           this.color=color;
           this.model= model;
           this.year=year;
}
        public void start(){
          System.out.println("The car is starting.");
   }
        public void stop(){
           System.out.println("The car has stopped.");
  }
}


  public class main{
         public static void main (String []args){
               Car myCar=new Car("Red","Toyota",2022);
           System.out.println("Car model:"+ myCar.model);
           myCar.start();
 }
}
+1 vote
answered Oct 28, 2024 by Namrata Patil (160 points)
  • Class is a blueprint or prototype from which objects are created.
  • Class is a collection of object. It represents the set of properties or methods that are common to all object of one type.
  • class is an logical entity in the object oriented programming language. It is consists of data member and member function.
0 votes
answered Dec 10, 2024 by Sara_ Isabela (140 points)

A classe é quando você cria uma estrutura para armazenar um valor dentro dela e esse valor é chamado de objeto ou modelo.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...