• 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 Class as the Basis of all Computation

  • Categories OOPS concepts, Java, OOPS
  1. Identify the statements listed below as assignment, increment, method invocation or object creation statements.
    1. petrol++;
    2. System.out.println ( “Simply”);
    3. cost = 720.50;
    4. Car myCar=new Car();

Ans.

    1. increment statement.
    2. method invocation statement.
    3. Assignment statement or variable initialization.
    4. new Object instantiation
  1. Read the following class carefully and answer the questions that follows:
class school{
int roll,mark;
String name;
school(){ //function 1
roll= 3856;
}
static void data(){ //function 2
mark=0;
name= "student"; //statement1
}
void show(){ //function 3
System.out.println(roll+" "+name+" "+mark);
}
}
    1. Name the instance variables.
    2. What is the name given to function 3?
    3. Name the class method? Explain why?
    4. Explain statement 1

Ans.

    1. The instance variables are roll, mark and name
    2. The function 3 is an instance/member function or user-defined function
    3. The name of the class method is data(). Because the keyword static makes a method as static or class method.
    4. The statement 1 is assignment or initialization of string constant to instance variable of string type name.
  1. Read the following class carefully and answer the questions that follows:
class school{
int roll;
String name;
school(){ //function 1
roll= 3856;
}
static void data(){ //function 2
double mark=0.0;
name= "student"; //statement1
}
void show(){ //function 3
System.out.println(roll+" "+name);
}
}
    1. Name the local variables.
    2. What is the name given to function 1?
    3. Name the global variables.
    4. Can variable mark be used in method show()? Justify.

Ans.

    1. The local variable is mark.
    2. The function 1 is a default or non-parameterized constructor
    3. The global variables are roll and name.
    4. No, because mark is a local variable to function data() so it cannot be used inside function show().
  1. Identify the type of constructors that are implemented in following class
Class Simply {
Int x, y;
Simply ();
Simply (Simply& b);
}

Ans.

Simply () – Default Constructor
Simply (Simply& b) – Copy constructor

  1. Give the output of the following program code when function Display() is invoked? Justify.
public class simply {
static double R=78.3;
public static void Show(){
double R= 75.0;
System.out.println(R);
}
public static void Print(){
System.out.println(R);
}
public void Display(){
Show();
Print();
}
}

Ans.

75.0 (variable R is assigned 75.0 and act as local variable)
78.3 (it has only print statement , so in this case the Global value R=78.3 activate and print)

  1. Consider the following class:
public class myClass{
public static int x=3, y=4;
public int a=2, b=3;
}
    1. Name the variables for which each object of the class will have its own distinct copy.
    2. Name the variables that are common to all objects of the class.

Ans.

    1. The variables: ‘a’ and ‘b‟ //(because these are non-static or instance variables)
    2. The variables : ‘x’ and ‘y‟ //(because these are static or class variables.)
  1. Rewrite the following program after removing the errors, underlining each correction:
class My Class
{
int a, b;
void initialize( )
{
MyClass
a=5;
b=6;
}
void show ( )
{
System.out.println (a+ ‘’ ‘’ + b);
}
static void main( )
{
My Class ob = new My Class ( );
initialize ( );
show ( ). ob; 
} 
}

Ans.

class MyClass
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show ( )
{
System.out.println (a+ ‘’ ‘’ + b);
}
static void main( )
{
MyClass ob = new MyClass( );
initialize( );
ob.show ( );
}
}
  1. Which among the following are invalid class names in Java? State with reasons.
    1. Simply Coding
    2. 1My Simply
    3. MySimply$
    4. Mysimply #
    5. My@ simply

Ans.

    1. Invalid, as a variable name cannot have a blank space.
    2. Invalid, as a variable name cannot begin with a digit.
    3. valid
    4. Invalid, as a variable name cannot have a special character, like #.
    5. Invalid, as a variable name cannot have a special character, like @.
  1. Consider the following code and answer the questions that follow:
class academic { int x,y; 
void access() 
{ 
int a,b; 
academic student=new academic(); 
System.out.println(“Object Created”); 
} 
}
    1. What is the object name of the class?
    2. Name the instance variables used in the class.
    3. Write the name of local variables used in the program.
    4. Give the type of function being used and its name.

Ans.

    1. student
    2. x and y
    3. a and b
    4. Procedural function or pure function.
      Name: access()
  1. Consider the following code and answer the questions that follow:
class vxl 
{ 
int x,y; 
void init( )   
{ x=5; y=10; 
} 
protected void access( )  
{ 
int a=50, b=100; 
vxl vin=new vxl( ); 
vin.int( ); 
System.out.println(“Object created”); 
System.out.println(“I am X=”+vin.x); 
System.out.println(“I am Y=”+vin.y); 
} 
}
    1. What is the object name of the class vxl?
    2. Name the local variables of class.
    3. What is the access specifier of method access( )?
    4. Write the output of the above program.

Ans.

    1. vin
    2. a and b
    3. protected
    4. Output:
      Object created
      I am X=5
      I am Y=10
  1. Find the errors in the program given below and rewrite the corrected form:
My class 
{ 
int a; 
int b; 
void display() 
{ 
System.out.printIn(a+“ ”+b); 
} 
static void display2() 
{ 
System.out.println(a+“ ”+b); 
} 
public static void main(String args[ ]) 
{ 
My class ob1=new My class( ); 
display1().ob1; 
display2().ob2; 
} 
}

Ans.

class Myclass 
{ 
int a; 
int b; 
void display1( ) 
{ 
System.out.println(a+“ ”+b); 
} 
void display2( ) 
{ System.out.println(a+“ ”+b); 
} 
public static void main(String args[ ]) 
{ 
Myclass ob1=new Myclass( );
Myclass ob2=new Myclass( ); 
ob1.display1();
ob2.display2(); 
} 
}
  1. In the program given below:
class MyClass 
{ 
static int x = 7; 
int y = 2; 
public static void main(String args[ ]) 
{ 
MyClass obj = new MyClass(); 
System.out.println(x); 
obj.sampleMethod(5); 
int a= 6; 
System.out.println(a); 
} 
void sampleMethod(int n) 
{ 
System.out.println(n); 
System.out.println(y); 
} 
}

State the name and value of the:

      1. (i) method argument or argument variable.
      2. (ii) class variable.
      3. (iii) local variable.
      4. (iv) instance variable.

Ans.

      1. (i) main() =String args[] value=none
        sampleMethod=int n value=5
      2. (ii) x value=7
      3. (iii) a value=6
      4. (iv) y value=2
  • Share:
author avatar
Simply Coding

Previous post

Java for and while loops questions for practice
June 11, 2020

Next post

Short questions on Java Functions
June 11, 2020

You may also like

Questions on Encapsulation
Questions on Encapsulation
4 July, 2021
Constructor Programs
Constructor Programs
3 July, 2021
Java Object Oriented Concepts
Java Object Oriented Concepts made easy
22 June, 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

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