Ask Question
12 February, 17:43

In Java Describe the relationship between an Object and a Class. Provide an example.

+2
Answers (1)
  1. 12 February, 21:18
    0
    Class are the collection of variable and function. Class are the blueprint of an object. class are the logical entity.

    Object are the physical entity. To access the properties of class we can create object of the particular class. We can create multiple object for a single class.

    Explanation:

    In java we can create the class by using the class keyword

    Following are the syntax of class

    class classname

    {

    / / function

    public static void main (String args[]) / / main method

    {

    / / statement

    }

    }

    In java the main method is inside the class.

    In java object are created for a particular class by using "new " keyword.

    Following are the syntax to create a object in java

    classname objectname=new classname ();

    Let us consider a simple example of class and object in Java.

    import java. io.*; / / import package

    class Text / / creating class

    {

    public void fun () / / memeber function fun ()

    {

    System. out. println (" hello"); / / print hello message

    }

    public static void main (String[] args) / / main method

    {

    Text ob=new Text (); / / creating object ob ...

    ob. fun (); //calling function fun by using object

    }

    }

    output

    hello
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “In Java Describe the relationship between an Object and a Class. Provide an example. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers