28 Questions
What is a class in Java comparable to in real life?
A blueprint for creating objects
What is the correct way to declare a class in Java?
public class Main {
What is an object in Java created from?
A class
What is the name of the Java file that should match the class name?
Main.java
What is the initial value of the variable x in the class Main?
5
What is the syntax to create an object of a class?
Main myObj = new Main();
What is the output of the code: public class Main { int x = 5; public static void main(String[] args) { Main myObj1 = new Main(); Main myObj2 = new Main(); System.out.println(myObj1.x); System.out.println(myObj2.x); } }
5, 5
What is the purpose of creating multiple objects of a class?
To create multiple instances of the class with different attributes
What is the rule for naming a Java file?
The file name must match the class name
What is the benefit of using multiple classes in Java?
It makes the code more organized
What is the main difference between procedural programming and object-oriented programming?
Procedural programming is about writing procedures, while object-oriented programming is about creating objects
What is the advantage of using OOP in terms of code maintenance?
OOP helps to keep the code DRY and makes it easier to maintain, modify, and debug
What is the relationship between a class and an object in OOP?
A class is a template for objects, and an object is an instance of a class
What is the principle of 'Don't Repeat Yourself' (DRY) in OOP?
Extracting out common codes and placing them at a single place to reuse them
What is the characteristic of OOP that makes it possible to create full reusable applications?
OOP makes it possible to create full reusable applications with less code and shorter development time
What is the programming language that is based on object-oriented programming?
Java
What is the term used for variables within a class?
Class Attributes
How do you access attributes in a class?
Using the dot syntax (.)
What is the output of running the 'Second.java' file?
It will print 5
What is the term used for 'x' in the example Main class?
Class Attribute
How do you compile 'Main.java' and 'Second.java' files?
Using the 'javac' command
What is the name of the class created in the 'Second.java' file?
Second
What is the output of the code when we print the value of x in the following code: public class Main { int x = 5; public static void main(String[] args) { Main myObj = new Main(); System.out.println(myObj.x); } }
5
What happens when we modify the attribute values in one object, but not in another?
The attribute values in only the modified object change.
How many attributes can you specify in a class?
As many as you want
What happens when we override the value of x with 25?
The value of x becomes 25.
What is the purpose of the x attribute in the following code: public class Main { int x = 5; ... }?
To store an integer value
What is the output of the code when we print the values of fname, lname, and age in the following code: public class Main { String fname = "John"; String lname = "Doe"; int age = 24; ... }?
Name: John Doe, Age: 24
Learn the basics of Object-Oriented Programming (OOP) in Java, including its advantages over procedural programming. Discover how OOP helps keep code organized and efficient.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free