Computer Science, asked by rajeswarirrr18, 9 months ago

How to declare a class and create object in java​

Answers

Answered by Anonymous
3

Answer:

To Create a class-

Create a class named "MyClass" with a variable x:

public class MyClass

int x = 5;

Remember from the Java Syntax chapter that a class should always start with an uppercase first letter, and that the name of the java file should match the class name.

Create an Object

In Java, an object is created from a class. We have already created the class named MyClass, so now we can use this to create objects.

To create an object of MyClass, specify the class name, followed by the object name, and use the keyword new:

Answered by Anonymous
2

Answer:

In Java, the new keyword is used to create new objects. Declaration − A variable declaration with a variable name with an object type. Instantiation − The 'new' keyword is used to create the object. Initialization − The 'new' keyword is followed by a call to a constructor.

Similar questions