• Register

No, const does not have any yield type in Java.

Const seems like function but it is not. It does not have a yield type and its name is same as the class name. Typically it is used to assign value to the inst var of a class.

Const is a chunk of code that resets the afresh produced obj. A const look like an inst function in java but it’s not a function as it does not have a return type. Shortly const and function are dissimilar. People frequently state const as distinct type of function in Java.

If the programmer doesn’t code a const the compiler codes a const on his own.


If you carefully see the statement of the const in the subsequent sample it just have the title of the const which is alike to class and, the parameters. It does not have any return type.

public class DemoTest1{
   String name1;
   int age1;
   DemoTest1(String name1, int age1){
      this.name1 = name1;
      this.age1 = age1;
      System.out.println("it is the const of the demoTest1");
   public static void main(String args[]){
      Scanner sc1 = new Scanner(System.in);
      System.out.println("Enter  name1: ");
      String name1 = sc1.nextLine();
      System.out.println("Enter age1: ");
      int age1 = sc.nextInt();
      DemoTest obj1 = new DemoTest(name1, age1);
      System.out.println("Value of the inst var name1: "+name1);
      System.out.println("Value of the inst var age1: "+age1);


Enter the value of name:


Enter the value of age:


This is the const of the democlass1

Value of the inst var name: Mubashir

Value of the inst var age: 23

2,760 points
7 4