0
0
Javaprogramming~5 mins

Classes and objects in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a class in Java?
A class is a blueprint or template that defines the structure and behavior (fields and methods) that objects created from the class will have.
Click to reveal answer
beginner
What is an object in Java?
An object is an instance of a class. It represents a real-world entity with state (data) and behavior (methods) defined by its class.
Click to reveal answer
beginner
How do you create an object from a class in Java?
You use the 'new' keyword followed by the class constructor. For example: <br> <code>ClassName obj = new ClassName();</code>
Click to reveal answer
intermediate
What is the purpose of a constructor in a class?
A constructor is a special method used to initialize new objects. It has the same name as the class and no return type.
Click to reveal answer
beginner
Explain the difference between fields and methods in a class.
Fields are variables that hold data about the object. Methods are functions that define the behavior or actions the object can perform.
Click to reveal answer
Which keyword is used to create an object in Java?
Anew
Bclass
Cobject
Dcreate
What does a constructor do in a Java class?
ADeletes objects
BDefines the class name
CInitializes new objects
DCalls methods
Which of the following is NOT a part of a class?
AObjects
BMethods
CFields
DConstructors
How do you call a method named 'run' on an object 'car'?
Arun.car();
Bcar.run();
Ccar->run();
Drun(car);
What is the correct way to declare a class named 'Dog'?
Aclass = Dog {}
BDog class {}
Cnew class Dog {}
Dclass Dog {}
Describe what a class and an object are in Java and how they relate to each other.
Think about how a cookie cutter (class) relates to cookies (objects).
You got /3 concepts.
    Explain the role of constructors in creating objects and how they differ from regular methods.
    Constructors prepare new objects when they are born.
    You got /4 concepts.