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

Java mini

The document outlines the examination instructions and model answers for a Java Programming course conducted by the Maharashtra State Board of Technical Education. It includes definitions, examples, and explanations of key concepts such as classes, objects, constructors, exceptions, and arrays in Java. Additionally, it provides guidelines for examiners on assessing student responses based on understanding rather than exact wording.

Uploaded by

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

Java mini

The document outlines the examination instructions and model answers for a Java Programming course conducted by the Maharashtra State Board of Technical Education. It includes definitions, examples, and explanations of key concepts such as classes, objects, constructors, exceptions, and arrays in Java. Additionally, it provides guidelines for examiners on assessing student responses based on understanding rather than exact wording.

Uploaded by

farooquishaban07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous) (Autonomous) (Autonomous)


(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

Winter – 19 EXAMINATION Ans Class: A class is a user defined data type which groups data Definition 1 1)One-Dimensional
members and its associated functions together. Mark each
Subject Name: Java Programming Model Answer Subject Code: 22412 2)Two-Dimensional
Object: It is a basic unit of Object Oriented Programming and g List access specifiers in Java. 2M
Important Instructions to examiners: represents the real life entities. A typical Java program creates Ans 1)public Any 2, 1M for
1) The answers should be examined by key words and not as word-to-word as given in the many objects, which as you know, interact by invoking methods. each
model answer scheme. 2)private
2) The model answer and the answer written by candidate may vary but the examiner may try c List the methods of File Input Stream Class. 2M
to assess the understanding level of the candidate. 3)friendly
Ans • void close() Any Two Each
3) The language errors such as grammatical, spelling errors should not be given more for 1 Mark
Importance (Not applicable for subject English and Communication Skills. • int read() 4)protected
4) While assessing figures, examiner may give credit for principal components indicated in the • int read(byte[] b)
figure. The figures drawn by candidate and model answer may vary. The examiner may give 5)Private Protected
• read(byte[] b, int off, int len)
credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant • int available() 2. Attempt any Three of the following: 12M
values may vary and there may be some difference in the candidate’s answers and model a Differentiate between String and String Buffer. 4M
answer. d Define error. List types of error. 2M
Ans Any 4 Points
6) In case of some questions credit may be given by judgement on part of examiner of relevant Ans • Errors are mistakes that can make a program go wrong. Errors Definition: 1m
String String Buffer c 4 Marks
answer based on candidate’s understanding. may be logical or may be typing mistakes. An error may List: 1m
7) For programming language papers, credit may be given to any other program based on produce an incorrect output or may terminate the execution of String is a major class String Buffer is a peer class
equivalent concept. the program abruptly or even may cause the system to crash. of String
Q. Sub Answer Marking
No. Q. N. Scheme
Errors are broadly classified into two categories: Length is fixed (immutable) Length is flexible (mutable)
1. Attempt any Five of the following: 10M
1. Compile time errors Contents of object cannot be Contents of object can be
a Define Constructor. List its types. 2M modified modified
Ans Constructor: A constructor is a special member which initializes Definition:1Mark 2. Runtime errors
an object immediately upon creation. It has the same name as Types: 1 Mark e List any four Java API packages. 2M Object can be created by Objects can be created by
class name in which it resides and it is syntactically similar to Ans 1.java.lang 1/2 Marks for assigning String constants calling constructor of String
2.java.util one Package
any method. When a constructor is not defined, java executes a enclosed in double quotes. Buffer class using “new”
default constructor which initializes all numeric members to zero 3.java.io
4.java.awt Ex:- String s=”abc”; Ex:- StringBuffer s=new
and other types to null or spaces. Once defined, constructor is
5.java.net StringBuffer (“abc”);
automatically called immediately after the object is created
before new operator completes. 6.ava.applet

Types of constructors: b Define a class circle having data members pi and radius.
f Define array. List its types. 2M
Ans An array is a homogeneous data type where it can hold only Definition 1 Initialize and display values of data members also calculate
1. Default constructor
Mark, List 1 area of circle and display it.
objects of one data type.
2. Parameterized constructor Mark Ans class abc correct
Types of Array: Program with
3. Copy constructor { correct logic 4
b Define Class and Object. 2M Mark

1|24 2|24 3|24

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

float pi,radius; a.area(); 1) drawRect()

abc(float p, float r) } 2)drawOval()


Ans 1)drawRect() : drawRect:
{ } 2Marks,
c Define exception. State built-in exceptions. 4M drawRect () method display an outlined rectangle. drawOval: 2
pi=p; Ans An exception is a problem that arises during the execution of a Definition 2 Marks
program. Marks, List: 2 Syntax: void drawRect(int top,int left, int width,int height)
radius=r; Marks
Java exception handling is used to handle error conditions in a The upper-left corner of the Rectangle is at top and left. The
} dimension of the Rectangle is specified by width and height.
program systematically by taking the necessary action
void area() Example: g.drawRect(10,10,60,50);
Built-in exceptions:
{ 2) drawOval( ): Drawing Ellipses and circles: To draw an
• Arithmetic exception: Arithmetic error such as division by
float ar=pi*radius*radius; zero. Ellipses or circles used drawOval () method can be used.
• ArrayIndexOutOfBounds Exception: Array index is out Syntax: void drawOval(int top, int left, int width, int height)
System.out.println("Area="+ar); of bound
} • ClassNotFoundException The ellipse is drawn within a bounding rectangle whose upper-
• FileNotFoundException: Caused by an attempt to access left corner is specified by top and left and whose width and
void display() a nonexistent file.
height are specified by width and height to draw a circle or filled
circle, specify the same width and height the following program
• IO Exception: Caused by general I/O failures, such as draws several ellipses and circle.
{
inability to read from a file. Example: g.drawOval(10,10,50,50);
System.out.println("Pi="+pi); • NullPointerException: Caused by referencing a null object.
• NumberFormatException: Caused when a conversion 3. Attempt any Three of the following:
System.out.println("Radius="+radius); a Explain the following classes. 4M
between strings and number fails.
i)Byte stream class
}} • StringIndexOutOfBoundsException: Caused when a
ii)Character Stream Class
program attempts to access a nonexistent character position
Ans i)Byte stream class: 2M for any two
class area in a string. points
• OutOfMemoryException: Caused when there’s not 1) InputStream and OutputStream are designed for byte
{
enough memory to allocate a new object. streams
public static void main(String args[]) • SecurityException: Caused when an applet tries to perform
an action not allowed by the browser’s security setting. 2) Use the byte stream classes when working with bytes or other
{ binary objects.
• StackOverflowException: Caused when the system runs out
abc a=new abc(3.14f,5.0f); of stack space. 3) Input Stream is an abstract class that defines Java’s model of
streaming byte input
a.display(); d Write syntax and example of : 4M

4|24 5|24 6|24

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

4)The Input stream class defines methods for performing input 4)contains any type of 4)contains only final variable
function such as reading bytes, closing streams, Marking variable
position in stream. 5)can have constructor 5)cannot have constructor
6)can have main() method 6)cannot have main() method
5) Output Stream is an abstract class that defines streaming byte
output. 7)syntax 7)syntax
Class classname Inteface Innterfacename
6) The output stream class defines methods for performing { {
output function such as writing bytes, closing streams Variable declaration, Final Variable declaration,
init ( ):The init( ) method is the first method to be called. This is Method declaration abstract Method declaration
ii)Character Stream Class: where you should initialize Variables. This method is called only } }
1. Reader and Writer are designed for character streams. once during the run time of your applet. d Define type casting. Explain its types with syntax and example. 4M
2. Use character stream classes when working with characters or Ans 1. The process of converting one data type to another is called 1M for
strings. start( ):The start( ) method is called after init( ).It is also called
casting or type casting. definition,3M for
3. Writer stream classes are designed to write characters. to restart an applet after it has Been stopped. Whereas init( ) is
types explanation
4. Reader stream classes are designed to read characters. called once—the first time an applet is loaded—start( )is called 2. If the two types are compatible, then java will perform the
5The two subclasses used for handling characters in file are each time an applet’s HTML document is displayed onscreen. conversion automatically.
FileReader (for reading characters) and FileWriter (for writing
characters). Paint ( ): The paint ( ) method is called each time your applet’s 3. It is possible to assign an int value to long variable.
output must be redrawn. Paint ( ) is also called when the applet
begins execution. Whatever the cause, whenever the applet must 4. However, if the two types of variables are not compatible, the
b Explain life cycle of Applet. 4M type conversions are not implicitly allowed, hence the need for
redraw its output, paint( ) is called. The paint ( ) method has one
Ans When an applet begins, the AWT calls the following methods, in 1M for diagram type casting.
parameter of type Graphics.
this sequence: ,3M for
explanation There are two types of conversion:
Stop ( ): When stop ( ) is called, the applet is probably running.
1. init( )
You should use stop ( ) to suspend threads that don’t need to run
when the applet is not visible. 1.Implicit type-casting:
2. start( )

3. paint( ) destroy( ): The destroy ( ) method is called when the environment 2.Explicit type-casting:
determines that your applet needs to be removed completely from
When an applet is terminated, the following sequence of method memory.
calls takes place:
1. Implicit type-casting:
c Differentiate between class and interfaces. 4M
4. stop( ) Ans 1M for each
point Implicit type-casting performed by the compiler automatically; if
Class Interface
5. destroy( ) there will be no loss of precision.
1)doesn’t Supports multiple 1) Supports multiple
inheritance inheritance
Example:
2)”extend ” keyword is used 2)”implements ” keyword is
to inherit used to inherit
int i = 3;
3) class contain method body 3) interface contains abstract
double f;
method(method without
f = i;
body)

7|24 8|24 9|24


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

Ans 2M for Running State: It means that the processor has given its time to
output: diagram,2M for the thread for execution. The thread runs until it relinquishes
f = 3.0 explanation control on its own or it is pre-empted by a higher priority thread.
Widening Conversion: Blocked state: A thread can be temporarily suspended or
blocked from entering into the runnable and running state by
The rule is to promote the smaller type to bigger type to prevent using either of the following thread method.
loss of precision, known as Widening Conversion.
1) suspend() : Thread can be suspended by this method. It
2. Explicit type-casting: can be rescheduled by resume().
2) wait(): If a thread requires to wait until some event
• Explicit type-casting performed via a type-casting occurs, it can be done using wait method and can be
operator in the prefix form of (new-type) operand. Thread Life Cycle Thread has five different states throughout its scheduled to run again by notify().
• Type-casting forces an explicit conversion of type of a life. 3) sleep(): We can put a thread to sleep for a specified time
value. Type casting is an operation which takes one period using sleep(time) where time is in ms. It re-enters
operand, operates on it and returns an equivalent value in 1. Newborn State the runnable state as soon as period has elapsed /over
the specified type.
2. Runnable State Dead State: Whenever we want to stop a thread form running
Syntax: further we can call its stop().The statement causes the thread to
3. Running State move to a dead state. A thread will also move to dead state
newValue = (typecast)value; automatically when it reaches to end of the method. The stop
4. Blocked State method may be used when the premature death is required.
Example: 5. Dead State b Describe final variable and final method. 4M
double f = 3.5; Ans Final method: making a method final ensures that the 2M for
Thread should be in any one state of above and it can be move definition,2M for
functionality defined in this method will never be altered in any
from one state to another by different methods and ways. example
int i; way, ie a final method cannot be overridden.
i = (int)f; // it cast double value 3.5 to int 3. Newborn state: When a thread object is created it is said to be in
Syntax:
Narrowing Casting: Explicit type cast is requires to Narrowing a new born state. When the thread is in a new born state it is not
conversion to inform the compiler that you are aware of the scheduled running from this state it can be scheduled for running final void findAverage()
possible loss of precision. by start() or killed by stop(). If put in a queue it moves to
runnable state. {

4. Attempt any Three of the following: //implementation


Runnable State: It means that thread is ready for execution and
a Explain life cycle of thread. 4M is waiting for the availability of the processor i.e. the thread has }
joined the queue and is waiting for execution. If all threads have
equal priority, then they are given time slots for execution in Example of declaring a final method:
round robin fashion. The thread that relinquishes control joins class A
the queue at the end and again waits for its turn. A thread can
relinquish the control to another before its turn comes by yield(). {

10 | 2 4 11 | 2 4 12 | 2 4

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

final void show() { 2) An array is a homogeneous 2) Vectors are heterogeneous.


data type where it can hold You can have objects of
{ public static void main(String args[]) only objects of one data type. different data types inside a
System.out.println(“in show of A”); { Vector.
} 3) After creation, an array is a 3) The size of a Vector can
boolean a = true;
fixed-length structure. grow or shrink as needed to
}
boolean b = false; accommodate adding and
class B extends A removing items after the
System.out.println("a && b = " + (a&&b)); Vector has been created.
{ 4) Array can store primitive 4) Vector are store non-
System.out.println("a || b = " + (a||b) ); type data element. primitive type data element.
void show() // can not override because it is declared with final
System.out.println("!(a && b) = " + !(a && b)); 5)Declaration of an array : 5)Declaration of Vector:
{
} int arr[] = new int [10]; Vector list = new Vector(3);
System.out.println(“in show of B”);
}} } 6) Array is the static memory 6) Vector is the dynamic
allocation. memory allocation.
Final variable: the value of a final variable cannot be changed. Output:
e List any four methods of string class and state the use of 4M
Final variable behaves like class variables and they do not take each.
a && b = false
any space on individual objects of the class. Ans The java.lang.String class provides a lot of methods to work on any four methods
a || b = true string. By the help of these methods, of string class
Example of declaring final variable: final int size = 100; can be
!(a && b) = true We can perform operations on string such as trimming, considered
c Explain any two logical operator in java with example. 4M
concatenating, converting, comparing, replacing strings etc.
Ans Logical Operators: Logical operators are used when we want to 2M for each
form compound conditions by combining two or more relations. operator with eg. d Differentiate between array and vector. 4M 1) to Lowercase (): Converts all of the characters in this String
Java has three logical operators as shown in table: Ans any four points to lower case.
1m for each point
Operator
Meaning Syntax: s1.toLowerCase()
&& Logical Array Vector
AND 1) An array is a structure that 1)The Vector is similar to Example: String s="Sachin";
|| Logical holds multiple values of the array holds multiple objects
OR same type. System.out.println(s.toLowerCase());
and like an array; it contains
! Logical
NOT components that can be Output: sachin
Program demonstrating logical Operators accessed using an integer
index. 2)to Uppercase():Converts all of the characters in this String to
public class Test upper case

13 | 2 4 14 | 2 4 15 | 2 4

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

Syntax: s1.toUpperCase() Ans import java.util.*; (Vector creation which classes are stored.
class VectorDemo with elements – 2 The syntax for defining a package is:
Example: { M, package pkg;
String s="Sachin"; public static void main(String[] args) Here, pkg is the name of the package
{ eg : package
System.out.println(s.toUpperCase()); Vector v = new Vector(); mypack; Package creation
v.addElement(new Integer(5)); Packages are mirrored by directories. Java uses file system - 2M
Output: SACHIN
v.addElement(new Integer(15)); directories to store packages. The class files of any classes which
3) trim (): Returns a copy of the string, with leading and trailing v.addElement(new Integer(25)); are declared in a package must be stored in a directory which has
whitespace omitted. v.addElement(new Integer(35)); Insert new same name as package name. The directory must match with the
v.addElement(new Integer(45)); element – 2M, package name exactly. A hierarchy can be created by separating
Syntax: s1.trim() System.out.println("Original array elements are package name and sub package name by a period(.) as
"); pkg1.pkg2.pkg3; which requires a directory structure as
Example:
for(int i=0;i<v.size();i++) Remove elements pkg1\pkg2\pkg3. Example - 3M
String s=" Sachin "; { 2 M, Syntax:
System.out.println(v.elementAt(i)); To access package In a Java source file, import statements
System.out.println(s.trim()); } (Any other logic occur immediately following the package statement (if
v.insertElementAt(new Integer(20),1); // insert can be it exists) and before any class definitions.
Output:Sachin
new element at 2nd position considered)
Syntax:
4) replace ():Returns a new string resulting from replacing all v.removeElementAt(0); (Note Any other
import pkg1[.pkg2].(classname|*); example can be
occurrences of old Char in this string with new Char. //remove first element Example: considered)
v.removeElementAt(3); package package1;
Syntax: s1.replace(‘x’,’y’)
//remove fourth element public class Box
Example: System.out.println("Array elements after insert {
and remove operation "); int l= 5;
String s1="Java is a programming language. Java is a platform."; for(int i=0;i<v.size();i++) int b = 7;
{ int h = 8;
String s2=s1.replace("Java","Kava"); //replaces all occurrences
System.out.println(v.elementAt(i)); public void display()
of "Java" to "Kava"
}}} {
System.out.println(s2); b Define package. How to create user defined package? 6M System.out.println("Volume is:"+(l*b*h));
Explain with example. }
Output: Kava is a programming language. Kava is a platform. Ans Java provides a mechanism for partitioning the class namespace (Definition of
}
into more manageable parts. This mechanism is the package. The package - 1M,
Source file:
package is both naming and visibility controlled mechanism.
5. Attempt any Three of the following: 12-Total Marks import package1.Box;
Package can be created by including package as the first statement
a Write a program to create a vector with five elements as (5, 6M class volume
15, 25, 35, 45). Insert new element at 2nd position. Remove 1st in java source code. Any classes declared within that file will
{
and 4th element from vector. belong to the specified package. Package defines a namespace in

16 | 2 4 17 | 2 4 18 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

public static void main(String args[]) } 2. Provide code in the applet to parse these parameters. The
{ } Applet access their attributes using the getParameter method.
Box b=new Box(); catch(InterruptedException e) The syntax is : String getParameter(String name);
b.display(); {System.out.println("odd thread interrupted"); Program
} } import java.awt.*;
} } import java.applet.*;
c Write a program to create two threads one thread will print 6M } public class hellouser extends Applet
even no. between 1 to 50 and other will print odd number class EvenOdd {
between 1 to 50. { String str;
Ans import java.lang.*; Creation of two
public static void main(String args[]) public void init()
class Even extends Thread threads 4M
{ {
{
new Even().start(); str = getParameter("username");
public void run()
new Odd().start(); str = "Hello "+ str;
{
} }
try
} public void paint(Graphics g)
{
{
for(int i=2;i<=50;i=i+2) 6. Attempt any Three of the following: 12 M g.drawString(str,10,100);
{ a Explain how to pass parameter to an applet ? Write an applet 6M }
System.out.println("\t Even thread :"+i); Creating main to to accept username in the form of parameter and print “Hello
}
sleep(500); create and start <username>”.
Ans Passing Parameters to Applet <HTML>
} objects of 2
(Explanation for <Applet code = hellouser.class width = 400 height = 400>
} threads: 2M • User defined parameters can be supplied to an applet
parameter <PARAM NAME = "username" VALUE = abc> </Applet>
catch(InterruptedException e) using <PARAM…..> tags.
passing - 3M, </HTML>
{System.out.println("even thread interrupted"); • PARAM tag names a parameter the Java applet needs to
(OR)
} run, and provides a value for that parameter.
import java.awt.*;
} • PARAM tag can be used to allow the page designer to
import java.applet.*;
} specify different colors, fonts, URLs or other data to be Correct Program
– 3M /*<Applet code = hellouser.class width = 400 height = 400>
class Odd extends Thread used by the applet.
<PARAM NAME = "username" VALUE = abc>
{ (Any other logic To set up and handle parameters, two things must be done.
</Applet>*/
public void run() can be 1. Include appropriate <PARAM..>tags in the HTML document.
public class hellouser extends Applet
{ considered) The Applet tag in HTML document allows passing the
{
try arguments using param tag. The syntax of <PARAM…> tag
String str;
{ <Applet code=”AppletDemo” height=300 width=300>
public void init()
for(int i=1;i<50;i=i+2) <PARAM NAME = name1 VALUE = value1> </Applet>
{
{ NAME:attribute name
str = getParameter("username");
System.out.println("\t Odd thread :"+i); VALUE: value of attribute named by
str = "Hello "+ str;
sleep(500); corresponding PARAM NAME.
}

19 | 2 4 20 | 2 4 21 | 2 4

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)

public void paint(Graphics g) } TA=t;


{ c Implement the following inheritance 6M DA=d; (Any other logic
g.drawString(str,10,100); } considered)
} public void Basic_Sal()
} {
System.out.println("Basic Salary
b Write a program to perform following task 6M :"+Basic_Salary);
(i) Create a text file and store data in it. }
(ii) Count number of lines and words in that file. void Total_Sal()
Ans import java.util.*; Create file and Ans interface Salary {
import java.io.*; store data : 3M, { (Interface: 1M, Display();
class Model6B double Basic Salary=10000.0; Basic_Sal();
{ void Basic Sal();
public static void main(String[] args) throws Exception double Total_Sal=Basic_Salary + TA + DA +
} HRA;
{
int lineCount=0, wordCount=0; class Employee System.out.println("Total Salary :"+Total_Sal);
String line = ""; Get lines and { }
BufferedReader br1 = new BufferedReader(new word count : 3M) String Name; }
InputStreamReader(System.in)); int age; Employee class: class EmpDetails
Employee(String n, int b) 2M, { public static void main(String args[])
FileWriter fw = new FileWriter("Sample.txt"); {
//create text file for writing { Gross_Salary s=new
(Any other logic Name=n; Gross_Salary("Sachin",20,1000,2000,7000);
System.out.println("Enter data to be inserted in
file: "); can be age=b; s.Total_Sal();
String fileData = br1.readLine(); considered ) } }
fw.write(fileData); void Display() }
fw.close(); {
BufferedReader br = new BufferedReader(new System.out.println("Name of Employee
FileReader("Sample.txt")); :"+Name);
while ((line = br.readLine()) != null)
System.out.println("Age of Employee :"+age);
{
lineCount++; // no of lines count } Gross_Salary
String[] words = line.split(" "); } class: 3M)
wordCount = wordCount + words.length; class Gross_Salary extends Employee implements Salary
// no of words count {
} double HRA,TA,DA;
System.out.println("Number of lines is : " +
Gross_Salary(String n, int b, double h,double t,double d)
lineCount);
System.out.println("Number of words is : " + {
wordCount); super(n,b);
} HRA=h;

22 | 2 4 23 | 2 4 24 | 2 4

You might also like