OOP Concepts in Java
28 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is a class in Java comparable to in real life?

  • A set of attributes and methods
  • A variable declaration
  • An object itself
  • A blueprint for creating objects (correct)

What is the correct way to declare a class in Java?

  • class Main {
  • java class Main {
  • public class main {
  • public class Main { (correct)

What is an object in Java created from?

  • A variable declaration
  • A Java server
  • A class (correct)
  • A set of attributes and methods

What is the name of the Java file that should match the class name?

<p>Main.java (A)</p> Signup and view all the answers

What is the initial value of the variable x in the class Main?

<p>5 (C)</p> Signup and view all the answers

What is the syntax to create an object of a class?

<p>Main myObj = new Main(); (D)</p> Signup and view all the answers

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); } }

<p>5, 5 (A)</p> Signup and view all the answers

What is the purpose of creating multiple objects of a class?

<p>To create multiple instances of the class with different attributes (A)</p> Signup and view all the answers

What is the rule for naming a Java file?

<p>The file name must match the class name (A)</p> Signup and view all the answers

What is the benefit of using multiple classes in Java?

<p>It makes the code more organized (D)</p> Signup and view all the answers

What is the main difference between procedural programming and object-oriented programming?

<p>Procedural programming is about writing procedures, while object-oriented programming is about creating objects (B)</p> Signup and view all the answers

What is the advantage of using OOP in terms of code maintenance?

<p>OOP helps to keep the code DRY and makes it easier to maintain, modify, and debug (C)</p> Signup and view all the answers

What is the relationship between a class and an object in OOP?

<p>A class is a template for objects, and an object is an instance of a class (B)</p> Signup and view all the answers

What is the principle of 'Don't Repeat Yourself' (DRY) in OOP?

<p>Extracting out common codes and placing them at a single place to reuse them (C)</p> Signup and view all the answers

What is the characteristic of OOP that makes it possible to create full reusable applications?

<p>OOP makes it possible to create full reusable applications with less code and shorter development time (C)</p> Signup and view all the answers

What is the programming language that is based on object-oriented programming?

<p>Java (B)</p> Signup and view all the answers

What is the term used for variables within a class?

<p>Class Attributes (B)</p> Signup and view all the answers

How do you access attributes in a class?

<p>Using the dot syntax (.) (B)</p> Signup and view all the answers

What is the output of running the 'Second.java' file?

<p>It will print 5 (C)</p> Signup and view all the answers

What is the term used for 'x' in the example Main class?

<p>Class Attribute (A)</p> Signup and view all the answers

How do you compile 'Main.java' and 'Second.java' files?

<p>Using the 'javac' command (D)</p> Signup and view all the answers

What is the name of the class created in the 'Second.java' file?

<p>Second (C)</p> Signup and view all the answers

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); } }

<p>5 (C)</p> Signup and view all the answers

What happens when we modify the attribute values in one object, but not in another?

<p>The attribute values in only the modified object change. (A)</p> Signup and view all the answers

How many attributes can you specify in a class?

<p>As many as you want (C)</p> Signup and view all the answers

What happens when we override the value of x with 25?

<p>The value of x becomes 25. (D)</p> Signup and view all the answers

What is the purpose of the x attribute in the following code: public class Main { int x = 5; ... }?

<p>To store an integer value (B)</p> Signup and view all the answers

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; ... }?

<p>Name: John Doe, Age: 24 (D)</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser