0% found this document useful (0 votes)
646 views

Java Question BPUT

1. The document discusses key concepts from chapters 6 and 7 on classes, libraries, and inheritance in Java. 2. Chapter 6 covers controlling access to class members, Java libraries, working with strings, using math libraries, and packages. Common errors include not clearly defining concepts and providing incorrect examples. 3. Chapter 7 discusses inheritance definitions and needs, types of inheritance, base and derived classes, visibility modes, function overloading and overriding, abstract classes and methods, and interfaces. Common errors include confusion between concepts and improper usage.

Uploaded by

SYAMANTA GARUD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
646 views

Java Question BPUT

1. The document discusses key concepts from chapters 6 and 7 on classes, libraries, and inheritance in Java. 2. Chapter 6 covers controlling access to class members, Java libraries, working with strings, using math libraries, and packages. Common errors include not clearly defining concepts and providing incorrect examples. 3. Chapter 7 discusses inheritance definitions and needs, types of inheritance, base and derived classes, visibility modes, function overloading and overriding, abstract classes and methods, and interfaces. Common errors include confusion between concepts and improper usage.

Uploaded by

SYAMANTA GARUD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter –Six

More about classes and libraries


Sr No Concepts Degree Levels of Errors generally committed
of Assignme
Importa nt
nce
1 Controlling ** L 1,L3 Definition not cleared , scope for each
access to access specifier is wrongly explained ,
members of example not given
class
2 Java libraries *** L1,L2 Improper Usage for Method ,
argument passed to each method
not specified correctly,

3 Working with ***** L1, L2,L3 Working of methods not explained


string correctly , difference between string
buffer and string data type not
cleared , working of comapreTo() &
equals( ) methods

4 Using math ***** L1,L2,L3 Argument passed to method not


library mentioned , return type not mentioned

5 packages * L1 Packages used for methods not


known

Level 1
1. What is the difference between length( ) and capacity( ) string function?
a. Explain the following string functions available in Java giving suitable
examples in each case:
b. Length ( )
c. substring ( )
d. concat ( )
e. trim ( )
f. toUpperCase ( )
g. toLowerCase( )
2. Name any four packages available in java.
3. What is an abstract class?
4. What is the difference between an abstract class and an interface?
5. How compareTo() & equals() differ from each other
6. Explain indexOf(char ch)
7. Explain power()
8. Explain the library function append()
9. Explain charAt(int a)

Level 2
1. What is a package? Why do we design a package?.
2. What members of a class out of private, protected and public are inheritable?
3. When do we declare a method or class ‘final’? Explain with example
4. When do we declare a method or class abstract? Explain with example
5. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:

String s = "ABC Micro Systems";


jTextField1.setText(s.length()+" ");
jTextField2.setText(s.toLowerCase());

6. What will be the contents of jTextField1 , jTextField2 , jTextField3 after executing the
followingcode
jTextField1.setText(Math.power(2.3));
jTextField2.setText(Math.round(2.3));

7. What will be the contents of jTextField1 , jTextField2 , jTextField3 after executing the
followingcode
String s1 = "ABC ";
String s2 =” Microsystem”
jTextField1.setText(s1.concat(s2));
jTextField2.setText(s1.length());
jTextField3.setText(s2.length());
8. What will be the contents of jTextField1 after executing the followingcode
String s1 = "ABC ";
jTextField1.setText(s1.replace (‘A’ , ‘H’));

9. What will be the contents of jTextField1 after executing the followingcode


String s1 = " ABC Microsystems";
jTextField1.setText(s1.trim());
10. What will be the contents of jTextField1 , jTextField2 , jTextField3 after executing the
followingcode
String s1 = "ABC ";
jTextField1.setText(s1.indexOf(‘C’));

Level 3
1. Write the code for an application count button that counts the occurrence of a
particular character in a string. 3 mark
2. Write the code that changes the first letter of each word in a textbox
touppercase and display the modified sentence in the same textbox. 4
3. An application that converts a string into its reverse and print its in RevTF. write the
suitable code for the application 3 mark
4. find output if ”abc”is passed as argument
Public static void func(string s1)
{
String s = s1+”xyz” ;
System.out.printlln(“ “ + s1);
System.out.printlln(“ “ + s);
}
5. find the output
stringBuffer city = new stringBuffer(“Madras”);
stringBuffer string = new stringBuffer(“ ”);
string.append(new string(city));
string.insert(0 , “Central”);
string.out.println(string);
6. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:
String s = "ABC Micro Systems";
jTextField1.setText(s.replace( ‘r’ , ‘t’);

7. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:
String s = " Informatics Practices ";
jTextField1.setText(s.toUppercase());
jTextField2.setText(s.trim());
8. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:
String s = " Informatics Practices ";
jTextField1.setText(s.conact(“ Practicals”));

9. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:
String s = " Informatics Practices ";
jTextField1.setText(s.lastIndexof(“s”);

10. What will be the contents of jTextField1 and jTextField2 after executing the
followingcode:
String s = " Informatics Practices ";
jTextField1.setText(s.substring( 0, 3));

Chapter -7
Inheritance
Sr.No Concept Importance Levels Errors
1 Definition & need *** 1,2,3 Generally no errors
2 Types of Inheritance ** 1,2 Confusion between Multi-
level & Multiple Inheritance

3 Base & Derived Class ***** 1,2,3 Improper definition of sub


class
4 Visibility Modes **** 1,2,3 Difference between
protected and public
visibility modes
5 Function Overloading *** 1,2,3 Confusion in type of
arguments
6 Function Overriding *** 1,2,3 Which of the function will be
called by which object
7 Abstract Class & ** 2,3 Generally No errors
Methods
8 Interfaces ** 2,3 Generally No errors

Level 1
1. What is Inheritance & What is the need of inheritance?
2. Name the various type of inheritance available in java.
3. Define the concept of Base Class and derived class.
4. What are the visibility modes in java?
5. What is the difference between function overloading and function overriding?
6. What is abstract class & methods?
7. Does Java support Multiple Inheritance? Yes or No.
8. What is the difference between protected and public visibility mode.
9. What is the default visibility mode if nothing is specified?
10. What is the difference between method prototype and method signature

Level 2

1. Name the various type of inheritance available in java.


2. Can a derived class have access to private members of base class?
3. When do we declare a method or class ‘final’?
4. What is an abstract class?
5. Differentiate between Interface and Multilevel Inheritance.
6. What is the sequence of constructor calling in inheritance?

Level 3
1. Why was the concept of inheritance introduced in object oriented Languages?
Write the Syntax and its body key points.
2. When do we declare a method or class abstract?
3. Differentiate between an abstract class and an interface?
4. Differentiate between Protected and Friendly access specifiers ?
5. Write a student class with following specifications:-
 Two private variables : first name, last name
 Constructor with two arguments
 Void Method printdata() to print first+lastname

Write a Graduate class that inherits from student class


 Add private variables, Stream, Degree
 It must have a constructor method
 Method PrintGrade() to print Stream, Degree along with inherited first and last
name.

6. When an overridden method is called through a Super class reference which


version of the method is executed ?

Answer to the Chapter -6


More about Classes and libraries
Level 1

1 Length() return the length while capacity() return maximum no of character that
can be entered.
2 Return length , extract substring , conacat string specified in argument, removes
the leading & trailing spaces, convert into upper & lowercase
3 Java.applet , java.awt, java.io, java.net
4 Abstract classes are used for inheritance
5 Abstract classes are used for inheritance while interface is used for multiple
inheritance
6 Compareto () compares 2 string while equals( ) check for equality
7 indexOf(char ch) returns the index of the Character Ch
8 Power(a,b ) finds the value of a raise to power b
9 Append() is used to append the string in a textarea to its p
10 charAt(int a) retruns the character present at position a in the string

Level 2
1. Related classes and interfaces grouped together is called as package.
2.
Member Type Its Own Derived Class
class Same Package Other Package
Public Accessible Accessible Accessible
Protected Accessible Accessible Accessible
Default Accessible Accessible Not Accessible
Private Protected Accessible Accessible Not Accessible
Private Accessible Not Accessible Not Accessible
3. Final keyword is used fro a class to make it static
4 Whenever a class contains only general code and need to be inherited .
5. (a) s.length() will give output -17
(b) jTextField2.setText(s.toLowerCase()) will give output abc micro systems
6 (a) 2
(b) 8
7. (a) ABC Microsytems
(b) 3
( c) 12
8. HBC

9. ABC Microsystems

10. 2
Level 3
1. string str = Tf.getText();
int len = str.length();
char ch =character.toUppercase();
str = ch + str.substring(1);
for (int I =2 ;i<len -1; i++)
{
If (str.charAt(i) == ‘ ‘)
{
Ch = character.toupperCase(str.charAt(i+1));
Str = str.substring(0,i+1) + ch +str.substring(i+2);
}
}
TF.setText(str);
2. string str = STF.getText();
char ch = charTF.getText().charAt(0);
int count = 0;
for(int i=0; i<str.length(); i++)
{
If(str.charAt(i) = = ch)
Count=count+1;
}
occurLable.setText(“”+ Count);
3. string str = STF.getText();
string strRev = “”;
for(int i=str.length()-1 ;i>0 ; i--)
{
strRev=strRev+ str.charAt(i);
}
Revtf.setText(strRev);
4. i. abc ii. Abcxyz
5. CentralMadras
6. ABC Micto Systems
7. i INFORMATICS PRACTICES ii Informatics Practices
8. Informatics Practices Practicals
9. 20
10. SPACE In
Chapter -7
Lesson-Inheritance
Level 1
Ans-1 Inheritance: The ability of a class to obtain the characteristics of another
class is called inheritance.
Need of Inheritance: Inheritance helps in two ways:
 Code Reusability:
 Helps in expressing relationship among classes
Ans -2 Type of Inheritance:
o Single Inheritance
o Multiple Inheritance
o Hierarchical Inheritance
o Multilevel Inheritance
o Hybrid Inheritance
Ans-3 Base Class (Parent Class): The Preexisting class which is being inherited
is called the base class or the parent class. It is also called a Super Class
Derived Class (Child Class): The new class which inherits the capabilities
from another pre-existing class is called the Derived Class or the Child Class.
It is also called Sub Class.
Ans-4 Public, Protected Default, Private Protected, Private and their scopes
Ans -5 Function Overriding:
o If a derived class method has the same name as that of the base class
then the derived class method overtakes (get higher preference) the
base class method. This is known as overriding of base class method.
Function overloading:
o Two or more functions in the same scope having the same name but
different signatures are said to be overloaded. For two functions to be
overloaded either they should have different number of arguments or
different order of arguments.
As-6 Abstract Class: A class that cannot be instantiated.
Abstract Method: A method without implementation.
As- 7 No
Level-2
Ans -1 Type of Inheritance:
o Single Inheritance: A single Base class is being inherited by a single
derived class.
o Multiple Inheritance: A single derived class inherits more than one
base class.(This type of inheritance is not supported in Java)
o Hierarchical Inheritance: A single base class is being inherited by
more than one child classes.
o Multilevel Inheritance: A child class act as a base class for anther
child class.
o Hybrid Inheritance: A combination of two or more of the above
inheritance pattern.
Ans- 2 No
Ans- 3 Final class cannot be inherited. Final methods, classes are used for security.
This is because Hackers extend some of important classes and substitute their
classes for the origin.
As-4 Abstract Class: A class that cannot be instantiated.
public abstract class shape
{
-----
----- }
Ans-5 An interface cannot implement any methods.
No variables can be inherited from interfaces.
Level 3
Ans 1 Reusability
Base Class & Derived Class
Ans-2 A concrete/abstract superclass is the one whose objects cannot be declared
and created. When
we need to define general characteristics and behavior of its subclass es.
Ans-3 a) An interface can be implemented by a class which is already a
subclass of
another class. A class which is already a subclass of another class
can’t extend an abstract class as well.
b) An abstract class can contain non abstract methods where as a
interface can’t contain non-abstract methods. All methods of an
interface must be abstract.
Ans-4 Protected member is accessible in non sub class of same package but
friendly is not Accessible.
Ans-5 1. Create the class Student
2. Declare data members & functions
3. Create another class graduate and extend the Student class
Ans- 6 It is determined by the type of the object being referred to at the time of call.

You might also like