• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

OOPS concepts

Questions on Encapsulation

  • Categories OOPS concepts, OOPS, Java

1.  Define Encapsulation.

Ans. Encapsulation is the process of bundling state (instance variables) and behaviour (methods) is a single unit (class).

2. What do you mean by scope and lifetime of a variable?

Ans.

  • The scope of a variable defines the area or range or section of the code in which the variable is visible.
  • The variables defined within a block are not accessible outside that block.
  • The lifetime of a variable refers to how long the variable exists before it is destroyed or goes out of scope.

3. Write in brief about following visibility modes :

    1. private
    2. public
    3. protected

Ans. The access specifer is used to control the accessibility of members of class. The details are as follows:

  1. private specifier : This keyword converts the data members and member methods in private mode and restricts the accessibility of these members outside the scope of the class, but these private members can only be accessed with the help of public methods of the same class.
  2. public specifier : This keyword allows the data and function(s) as public interface which can be accessed within the class itself as well as outside the scope of the class or sub-class.
  3. protected specifier : This keyword converts the members (data and function(s)) in protected mode, so the protected members can be accessed through either its own class or by the subclass.

 

4. Differentiate between private and protected visibility modifiers.

Ans. private members are accessible only in the class in which they have been defined. Protected members are accessible in the class in which they have been defined as well in the sub classes of that class.

5. How are private members of a class different from public members?

Ans. Private members of a class can be accessed only by the methods of the class in which they are declared. While public members can be accessed outside of the class also.

6. What are member variables? State their types?

Ans:

  • Member variables are also known as Instance variables.
  • These member variables are used to store value in the class.
  • It may be public, private and protected, where private and protected members remains hidden from outside world and there by support data.

7. Define the term Local variable and Global variable?

Ans: Local Variable: Variable declared inside a method or block.

Global Variable: Class variable which is available to the entire class.

8. What is class variable? Give an example?

Ans.

  • Class variables are those variables which are initialized inside the class and outside of all of the blocks with static prefix.
  • The scope of a class variable is throughout the class in which that variable is declared.
  • Class variables support access specifiers.
class Example{
     public static int x;  //Class Variable
     static int num;      //Class Variable                         

     Void method1(){
          //statements..
     }
                        
    public static void main(){
          //statements.
    }
}
  • Share:
author avatar
Simply Coding

Previous post

Questions on Library classes
July 4, 2021

Next post

ISC Class 12 Computer Science previous year paper (2019)
July 10, 2021

You may also like

Questions on Library classes
Questions on Library classes
4 July, 2021
Questions on String 1
What is Java String?
3 July, 2021
Constructor Programs
Constructor Programs
3 July, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now