Untitled

public
pavankumarrajama Nov 06, 2024 Never 9
Clone
Java paste1.java 13 lines (10 loc) | 247 Bytes
This code defines a class named "constructor" with two public instance variables: "name" of type String and "age" of type int. It also includes a constructor within the class that initializes these variables when an object of the class is created. In the main method, it creates an object "c" of the constructor class using the constructor that takes two arguments - a String "pavan" and an integer 25. This object is then initialized with the specified values for the name and age. Overall, this code demonstrates the concept of classes and object instantiation in Java.
1
class constructor {
2
public String name;
3
public int age;
4
5
public constructor(String name, int age) {
6
7
this.name = name;
8
this.age =age;
9
}
10
}
11
12
public static void main(String args[]) {
13
constructor c = new constructor("pavan",25);