You are on page 1of 8

Chapter 5 - Java Classes

Q1. What is an object ?

ans. An object is an identifiable entity with some characterstics and behavior. variable declared of a class
is called an object

rect k=new rect() // k is an instance or object of class rect

Q2. What is a class?

ans. A class is a blueprint that represents a set of similar objects and their behavior. for eg.

class student

int roll,hindi,english,maths,social,science;

String name,sclass,sec,city;

void setdata(int rr,String nn,String cc,String ss,String ct)

roll=rr;

name=nn;

sclass=cc;

sec=ss;

city=ct;

void getresult()

void printdata()
{

System.out.println("Roll is"+roll);

in the above diagram student is a class which is a collection of variable methods and data members.

data members - roll,name,class,sec,city,hindi,english,maths,social,science

methods - setdata() , getresult(), printdata()

Q4. What are access specifiers?

ans. access specifiers are the keywords used to determine the tpe of access to the method or variable.
there are four types of access specifiers

1. Default - default access specifier of java (if no-one is specified)

2. Public - accessible anywhere

3. Private - accesiible only within the block/class where it is declared

4. Protected - accessible only with the class and its subclass.

Q5. What is a method prototype or signature ?

Ans.

A method prototype of signature is a model or declartion of method which identifies the parameters
and return type of that method.

for eg. int sum(int p,int q) // this prototype is indicating that the function sum will return an integer
and takes two integers as parameters
Q6. What are actual and formal parameters ?

Ans.

Actual Parameters - these are the parameters that are actually passed to a function call.

Formal Parameters - these are the parameters that are received during the function defination.

for eg.

static int sum(int p,int q) // p and q are formal parameters

int r;

r=p+q;

return(r);

public static void main(String args[])

int a,b,c;

a=6;

b=3;

c=sum(a,b); // here a and b are actual parameters

System.out.println("sum is "+c);

Q7. What is pass by value/pass by reference or call by value/call by reference ?

Ans.

Call by value : In this method copy of actual parameters are passed into the formal parameters and
whatever changes are made in formal parameters are not reflected back to the actual parameters.

Call by reference : in this method reference of actual parameters is passed into the formal paramters
and whatever changes are made in formal parameters are reflected back to the actual parameters.
normally it has object as function arguments.
Q8. What is scope and lifetime of a variable ?

Ans. The program part i which a particular piece of code or a data value can be accessed is known as
scope. visibility is also referred to as scope. Lifetime of a variable refers to the time to which a variable
lives in the program.

Q9. What is a constructor ?

Ans. A function having the same name as of the class is called a constructor. It is called automatically
upon creation of object of that class. It is used for initialization of data members of the class.

Q10. What are the types of constructor?

Ans. There are two types of constructor -

a. Parameterized constructor - rect(a,b)

b. Non Parameterized constructor - rect()

Q11. What is a default constructor ?

Ans. A constructor with no parameters and no body is called deafult const.

Q12. What is "THIS" object?

Ans. The keyword "THIS" refers to the currently calling object. It is automaically created and initialized
by Java.

CHAPTER 6 - More about classes and libraries

Q1. What is the difference between String and StringBuffer ?

Ans.
String String Buffer

----------------------------------------------------- -----------------------------------------------------

1. String in java are immutable StringBuffer objects are mutable

2. String Object once created can't be changed StringBuffer objects can be changed,
modified as desired

3. It contains less number of methods as compare to StringBuffer StringBuffer contains a large set
of additional methods to modify strings.

Q2. What is a package in java ?

Ans. Packages are groups of related classes and interfaces related to a particular category. Java has a
large set of inbuilt packages like java.io.*, java.sql. etc.

We can also create our own packages. To include a package in a program we have to use import
statement at the top of program.

Chapter 7 - Concept of Inheritance

Q1. What is inheritance?

Ans. It is the most important concept of Object oriented programming. Inheritance is the capabiity of
one class to inherit properties and methods from an another class. Major objective of inheritance is
resuability

Q2.What are the types of inheritance?

Ans. There are five types of inehritance

1. Single inheritance

2. Multiple inheritnce

3. Multilevel Inheritance
4. Hierarchical Inheritance

5. Hybrid Inheritance

NOTE : multiple and hybrid inheritance is not supported in java. we have to use interfaces to implement
them.

Q3. What is a Derived class?

Ans. A derived class or a subclass is the class which inherits the properties and methods of another class

Q4. What is a Base class?

Ans. A Base class or a superclass is the class which is derived into an another class.

Q5. What is a final variable ?

Ans. A variable whose value can't be changes is called final variable. it is declared as follows :

final int a=5;

Q6. What is a final method ?

Ans. A method which can be overridden is called a final method?

Q7. What is a final class ?

Ans. A final class is a class which can't be inherited.

Q8. What is an abstract class?

Ans. An abstrat class is the once that simply represents a concept and whose objects can't be created. It
is created through the use of keyword abstract.

Q9. What s a Abstract Method?


Ans. An abstract method is a method which do not have method statements or method body. it is
declared as follows :

abstract void display();

Q10. What is an interface ?

ans. Interface is just like abstract class, it is used to implements multiple inheritance in java.

Q11. What is method overloading ?

Ans. It refers to the concept where a class contains more than one methods with same name but with
different signatures.

MOST IMPORTANT DIFFERENCES

RadioButton Checkbox

---------------------------------------------------------------------------------------------------------------------------

1. Only one of multiple radiobuttons can be selected more than once checkboxes can
be selected among multiple checkboxes

2. Buttongroup is used to implement radiobutton no use of buttongroup in checkboxes

3. It is round shaped it is rectangular shaped control

PasswordField TextField

------------------------------------------------------------------------------------------------------------------------
1. Characters written in this are encrypted characters are visible as they
are written

2. we have to use echochar property no use of echochar property

LISTBOX ComboBox

-----------------------------------------------------------------------------------------------------------------------------------

1. More than one items are displayed at a time Only one item can be displayed
at a time.

2. More than one items can be selected at a time Only one item can be selected
at a time.

TextField TextArea

------------------------------------------------------------------------------------------------------------------------------------

1. It is used to input single line text It is used to enter multiline text

2. No scrollbars are displayed Horizontal and Vertical


scrollbars are displayed

3. setText() method is used to enter text append() method is used to


enter Text

You might also like