Ask Question
11 April, 04:46

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

+1
Answers (1)
  1. 11 April, 07:04
    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?
Get an answer to your question ✅ “In Java Describe the relationship between an Object and a Class. Provide an example. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers