Ask Question

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

+2
Answers (1)
  1. 11 March, 15:32
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers