By Sweta Sinha
An object is created from a class. In Java, the new keyword is used to create new objects. A class acts as a blueprint for the objects.
CREATING AN OBJECT IN JAVA
This project is about creating objects in Java. In Java, no program will execute without creating an object. Using a new keyword is the most popular method of creating an object in Java. In Java everything is related to classes and objects.Creating an object in Java is important as it calls variables and methods of a class.
importjava.io.*; public class Aniaml { public Animal(String name) //This constructor has one parameter,name// System.out.println("Passd Name is:"+name); } public static void main(String[] args) //Following statement would create an object myAnimal { Animal myAnimal= new Animal("Scooby"); } Output: Passed Name is:Scooby
Submitted by Sweta Sinha (Sweta321)
Download packets of source code on Coders Packet
Comments