QA Interview Handbook
  • ๐Ÿ Home Page
  • About Testing
    • ๐Ÿ’–Qualities of A Great Tester
  • Manual Testing
    • ๐Ÿ’กOverview
      • โœ‹Demand for Software Testing
      • ๐Ÿ˜„Tester's Role in Manual Testing
      • 7๏ธTesting Principles
      • ๐ŸšจV & V
      • โ”Interview Questions
    • โ™ป๏ธSDLC
      • ๐Ÿ“’Phase 1: Planning
      • ๐Ÿ”Phase 2: Requirement Analysis
      • ๐Ÿ‘”Phase 3: Design
      • โ›‘๏ธPhase 4: Development
      • ๐ŸงชPhase 5: Testing
      • ๐ŸššPhase 6: Deployment
      • ๐Ÿ–ฑ๏ธPhase 7: Maintenance
      • โš”๏ธCommon Challenges
      • โ”Interview Questions
    • ๐ŸŒ€STLC
    • ๐ŸŒŠWaterfall
    • โœณ๏ธAgile
      • ๐Ÿ˜Tester's Role in Scrum
    • ๐Ÿ”ขTypes
      • โฌœWhite Box Testing
      • โฌ›Black Box Testing
        • ๐Ÿ”ฐTechniques Used in Black Box Testing
        • ๐Ÿš˜Functional Testing
          • 1๏ธโƒฃUnit Testing
          • 2๏ธโƒฃIntegration Testing
            • ๐Ÿ”ฐTechniques Used in Integration Testing
          • 3๏ธโƒฃSystem Testing
            • ๐Ÿ“ผTypes of System Testing
            • ๐ŸŒŠPhases of System Testing
            • ๐ŸŒ€Regression Testing
            • ๐ŸŒซ๏ธSmoke Testing
          • 4๏ธโƒฃAcceptance Testing
            • โš™๏ธUser Acceptance Testing
            • ๐Ÿ…ฐ๏ธAlpha Testing
            • ๐Ÿ…ฑ๏ธBeta Testing
        • ๐Ÿ•ณ๏ธNon Functional Testing
      • ๐Ÿ“‘Grey Box Testing
    • ๐Ÿช„User Story
      • โบ๏ธSample User Stories
    • ๐Ÿ““Test Cases
      • โบ๏ธSample Test Cases
      • โ”Interview Questions
    • โœ–๏ธDefect Life Cycle
      • โ˜ฃ๏ธPriority + Severity
      • โบ๏ธSample Defect Reports
      • โ”Interview Questions
      • ๐Ÿ›Buggy Questions
    • ๐ŸŒAtlassian JIRA
      • ๐ŸžJIRA Issues
      • โ”Interview Questions
    • โ”Interview Questions
  • Accessibility Testing
    • ๐Ÿ’กOverview
    • ๐Ÿค“Tester's Role in Accessibility Testing
    • ๐Ÿ“šWCAG Principles
      • ๐Ÿ‘๏ธPerceivable
      • ๐ŸนOperable
      • ๐Ÿง Understandable
      • ๐Ÿค–Robust
    • ๐Ÿ”งAxe DevTools
      • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • โ”Interview Questions
  • API Testing
    • ๐Ÿ’กOverview
    • ๐Ÿ˜€Tester's Role in API Testing
    • ๐ŸŠHTTP Methods & CRUD
      • ๐Ÿ‚HTTP Status Codes
    • ๐ŸAPI Tools
      • ๐ŸŸ Postman
        • โ˜„๏ธSending your first API request
        • ๐Ÿ”ฌHTTP Requests with Java
        • ๐ŸŽฒGitHub Sample
        • โ”Interview Questions
      • โ›‘๏ธREST Assured
        • ๐ŸŽ‡Dependency
        • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • ๐ŸฆงAPI Cheatsheet
    • โ”Interview Questions
  • Database Testing
    • ๐Ÿ’กOverview
    • ๐Ÿ˜†Tester's Role in Database Testing
    • ๐Ÿ”ตSQL
      • โ›“๏ธConstraints
      • ๐Ÿ›ข๏ธReferencing a Column
      • ๐Ÿ”ผDDL Commands
      • ๐Ÿ”ผDML Commands
        • ๐Ÿ–Œ๏ธOperators
        • ๐Ÿ› ๏ธFunctions
          • โฏ๏ธAggregate Functions
        • ๐ŸŽ…Clauses
          • โซJoin Clauses
          • ๐Ÿ”ตFilter Clauses
          • โฌSet Operations
      • ๐ŸƒWildcard Character
      • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • ๐ŸงคSQL Practice Sites
    • ๐ŸซSQL Cheatsheet
    • โ”Interview Questions
  • Java
    • โ›ฉ๏ธIntroduction
    • ๐Ÿ˜„Tester's Reason to Learn Java
    • โ“‚๏ธMain Method
      • โ”Interview Questions
    • ๐Ÿ“Variables & Types
      • ๐ŸชขSpecial Types
    • ๐ŸฅModifiers
    • ๐Ÿ…พ๏ธOperators
    • ๐ŸชกString
      • ๐ŸฉบString Methods
        • String Method Problems
      • ๐ŸšจDelimiter
      • โ”Interview Questions
    • ๐Ÿ–‡๏ธConditionals
      • ๐Ÿ’ŽCommon If Statements
      • ๐Ÿ’ŽCommon Ternary Operator Statements
    • โ“‚๏ธMath Class
    • ๐ŸŒŠLoops
      • ๐Ÿ’ŽCommon Loop Examples
      • ๐Ÿ”ƒNested For Loops
    • ๐ŸผOOPS
      • ๐Ÿ›๏ธClasses and Objects
        • โ”Interview Questions
      • ๐ŸŽƒConstructor
        • โšกStatic
          • โ”Interview Questions
        • ๐Ÿ“This() & Super()
          • โ”Interview Questions
        • ๐Ÿ€Finalization
      • ๐Ÿ”“Encapsulation
      • ๐ŸฅInheritance
      • ๐Ÿฆ‹Polymorphism
      • ๐Ÿ•ธ๏ธAbstraction
    • ๐ŸฎJava Practice Sites
    • โ˜‘๏ธData Structures + Algorithms
      • ๐Ÿ…พ๏ธBig O
      • โ˜‘๏ธData Structures
        • ๐Ÿ”ธArray
        • ๐Ÿ”ณArray Problems
        • Page
      • ๐ŸชŸSliding Window Technique
        • ๐ŸชŸSliding Window Problems
        • ๐ŸฅLeetCode #53
        • ๐ŸฅLeetCode #209
    • โ”Interview Questions
  • Automation Testing
    • ๐ŸšฐFlow
      • ๐Ÿ’กOverview
      • ๐ŸคฉTester's Role in Automation Testing
      • ๐Ÿ€Selenium
        • ๐Ÿ•ธ๏ธSelenium WebDriver
          • ๐Ÿ•ท๏ธWebDriver Commands
            • ๐ŸŒWebElement
              • ๐Ÿ”†HTML Tags
              • ๐Ÿ”ฌFind Element(s)
              • ๐ŸฆŽLocators
                • โŒXpath
                • ๐ŸฐCSS Selector
                • ๐Ÿ“€DOM
                • ๐Ÿ Quick Reference for XPath + CSS
            • โœ‹Waits
            • Browser Management
            • ๐ŸŽ๏ธNavigation
            • Alerts
          • ๐Ÿท๏ธAdvanced User Interactions
            • ๐Ÿ—ฏ๏ธAction vs. Actions
            • ๐Ÿ’งDrop Down
            • โœ…Check Box
            • ๐Ÿ–‡๏ธForms
          • โš ๏ธExceptions
        • ๐ŸOOPS + Selenium
        • ๐ŸšขFrameworks
          • โš“Module Based Framework
          • ๐ŸŽนKeyword Driven Framework
          • ๐ŸŽ‹Data Driven Framework
          • ๐ŸŒบHybrid Framework
          • ๐ŸŒดLog4j
          • ๐Ÿ“„Page Object Model
        • ๐ŸงชTesting Frameworks
          • ๐Ÿ’กTestNG
          • ๐Ÿ‰‘JUnit
          • ๐Ÿฅ’BDD
            • ๐Ÿฅ’Cucumber
        • ๐ŸŒ‰Selenium Grid
          • โœ–๏ธDesired Capabilities
        • โ”Interview Questions
      • ๐Ÿ”„API Testing with Selenium
      • โชDatabase Testing with Selenium
      • โ“‚๏ธMaven
      • ๐Ÿ™Git
        • โ”Interview Questions
      • ๐Ÿ•ต๏ธโ€โ™‚๏ธJenkins
        • โ”Interview Questions
      • ๐ŸณDocker
        • โ”Interview Questions
      • ๐Ÿ“™AWS
        • โ”Interview Questions
  • Behavioral
    • ๐Ÿ“ฃMixed Interview Questions
    • โญSTAR Method
      • ๐ŸŒŸSample Responses
Powered by GitBook
On this page
  • ๐Ÿ—๏ธ What is a Class?
  • ๐Ÿ›๏ธ Rules for Classes and Objects in Java ๐Ÿ›๏ธ
  • ๐Ÿ“œ Rules for Classes ๐Ÿ“œ
  • ๐ŸŽ Rules for Objects ๐ŸŽ
  • ๐Ÿค“ Key Notes
  • ๐Ÿ’Ž In Simple Terms
  • ๐Ÿฅฝ What is an Object?
  • ๐Ÿƒ Key Notes

Was this helpful?

  1. Java
  2. OOPS

Classes and Objects

๐Ÿ—๏ธ What is a Class?

A class is essentially a template or blueprint that defines what objects within a Java program will look like and be able to do. Think of it like a cookie cutter - the class is the mold that objects get "baked" from during runtime.

Within a class you define variables and methods. Variables store data, like a cookie's shape and color. Methods are actions the objects can perform, like rotating or growing.

When you create a class, it doesn't actually make any objects yet. But any objects created with "new" will be of that class type.

For example:

public class Person {

  //Within the curly brackets is where you'll define your variables and methods.
  
}

The Person here is a class. It acts as a blueprint for creating Person objects.

๐Ÿ›๏ธ Rules for Classes and Objects in Java ๐Ÿ›๏ธ

Classes and objects are fundamental concepts in Java's object-oriented programming paradigm. There are certain rules around defining and using classes and objects.

๐Ÿ“œ Rules for Classes ๐Ÿ“œ

Some key rules for defining classes in Java are:

  • A class must have a name that is a valid identifier

  • The class body must be between opening and closing braces {}

  • A class can contain fields, methods, constructors, nested classes etc.

  • Fields and methods can have any access modifier (public, private, protected, default)

  • Only one public class per source file is allowed

For example:

public class Person {

  private String name;

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

}

This defines a Person class with a private field and public constructor.

๐ŸŽ Rules for Objects ๐ŸŽ

Some important rules related to objects are:

  • Objects must be instantiated using the new keyword before use

  • Data fields in an object can be accessed using the . operator

  • Methods of an object can be invoked using the . operator

  • The this keyword refers to the current object instance

  • Objects in Java are passed by reference, not value

For example:

Person person = new Person("John"); 

System.out.println(person.name); // Access field

person.walk(); // Call method

This creates a Person object and accesses its fields and methods.

So those are some of the key rules around defining and working with classes and objects in Java. Following these rules allows creating robust object-oriented code.

๐Ÿค“ Key Notes

  • A class is declared using the class keyword

  • It describes what attributes and behaviors an object will have

  • Objects are created (instantiated) based on the class

  • The class is a template, objects are instances of the template

So in summary, a class provides a definition for the attributes and behaviors of objects that will be created from it. It's a blueprint describing what the object will contain.

๐Ÿ’Ž In Simple Terms

A class is like a mold for making objects - it defines what the objects made from that mold will be like.

Objects are created from a class mold that describes them. The class itself is just the template, not the actual object.

So in Java, you define classes which act as blueprints for objects!

๐Ÿฅฝ What is an Object?

An object in Java is an instance of a class. It is created from a class blueprint and contains its own state and behaviors.

For example:

public class Person {
  // Class definition
}

Person obj = new Person(); // Object instantiation 

Here obj is an object of type Person that is instantiated from the Person class.

๐Ÿƒ Key Notes

  • An object is an instance of a class

  • It is created via new keyword from a class

  • It has its own set of attributes and behaviors

  • Multiple objects can be made from a single class

So an object is basically a real world entity represented inside a program.

Class and Object Problems
  1. What is a class? (A template that defines common properties and behaviors of an object)

  2. What is an object? (An instance of a class)

  3. How do you define a class in Java? (Use the class keyword followed by the name)

  4. How do you create an object from a class? (Use the new keyword followed by the class name)

  5. How do you add data fields/attributes to a class? (Define variables within the class)

  6. How do you add methods to a class? (Define functions within the class using the public or private keyword)

  7. How do you access object attributes? (Use dot notation objectname.attribute)

  8. How do you access object methods? (Use dot notation objectname.method())

  9. What is a constructor? (A special method that creates and initializes an object)

  10. How do you pass values to a constructor? (Include parameters in the constructor definition and pass them when creating the object)

PreviousOOPSNextInterview Questions

Last updated 1 year ago

Was this helpful?

๐Ÿผ
๐Ÿ›๏ธ