Answer to Question #126197 in Java | JSP | JSF for seth dacha

Question #126197

Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. Use your examples to illustrate the descriptions.


1
Expert's answer
2020-07-14T08:43:38-0400

Class example:

public class Cat{
private String name;

public Cat(String name){
this.name = name;
}

public void showCatName(){
System.out.println("Cat name is: " + name);
}
}

Object example:

Cat myCat = new Cat("Tommy");


A class is a description of an entity using a programming language. In order to use the functionality of a class (most often), you need to create its object. An object is a data type that allows you to use the functionality described in the classes. The relationship between a class and an object can be described as: the object is an instance of the class.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS