SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
abishekvk@outlook.com
1. Which of these is correct way of inheriting class A by class B?
a) class B + class A {}
b) class B inherits class A {}
c) class B extends A{}
d) class B extends class A {}
2. Which of the following statements are incorrect?
a) public members of class can be accessed by any code in the program.
b) private members of class can only be accessed by other members of the class.
c) private members of class can be inherited by a sub class, and become protected
members in sub class.
d) protected members of a class can be inherited by a sub class, and become private
members of the sub class.
3. What is the output of this program?
class A {
int i;
void display() {
System.out.println(i);
}
}
class B extends A {
int j;
void display() {
System.out.println(j);
}
}
class inheritance_demo {
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 0
b) 1
c) 2
d) Compilation Error
4. What is the output of this program?
abishekvk@outlook.com
class A {
int i;
}
class B extends A {
int j;
void display() {
super.i = j + 1;
System.out.println(j + " " + i);
}
}
class inheritance {
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 2 2
b) 3 3
c) 2 3
d) 3 2
5. What is the output of this program?
class A {
public int i;
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
System.out.println(super.i + " " + super.j);
}
}
class inheritance {
public static void main(String args[])
{
B obj = new B();
abishekvk@outlook.com
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
6. What is the output of this program?
class A {
public int i;
public int j;
A() {
i = 1;
j = 2;
}
}
class B extends A {
int a;
B() {
super();
}
}
class super_use {
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
7. What is the output of this program?
class A {
abishekvk@outlook.com
public int i;
protected int j;
}
class B extends A {
int j;
void display() {
super.j = 3;
System.out.println(i + " " + j);
}
}
class Output {
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 1 2
b) 2 1
c) 1 3
d) 3 1
8. A class member declared protected becomes member of subclass of which type?
a) public member
b) private member
c) protected member
d) static member
9. Which of the following is true about inheritance in Java?
1) Private methodsare final.
2) Protectedmembersare accessiblewithinapackage and
inheritedclassesoutside the package.
3) Protectedmethodsare final.
4) We cannot override privatemethods.
a) 1,2 and 4
b) Only 1 and 2
c) 1,2 and 3
d) 2,3 and 4
abishekvk@outlook.com
10. What will be the output of this program?
class A
{
int b = 50;
}
class B extends A
{
int b = 20;
}
public class MainClass
{
public static void main(String[] args)
{
A a = new B();
System.out.println(a.b);
}
}
a) Compiler error
b) 20
c) 50
d) None of the above
11. What is the output of this program?
import java.io.*;
class filesinputoutput {
public static void main(String args[]) {
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
Note: inputoutput.java is stored in the disk.
a) true
b) false
c) prints number of bytes in file
d) prints number of characters in the file
12. Which of these class can be used to implement input stream that uses a character array
as the source?
a) BufferedReader
b) FileReader
c) CharArrayReader
d) FileArrayReader
13. What is the output of this program?
import java.io.*;
class Chararrayinput {
abishekvk@outlook.com
public static void main(String[] args) {
String obj = "abcdef";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0,length,c,0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 0, 3);
int i;
try {
while ((i = input1.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
a) Abc
b) Abcd
c) Abcde
d) Abcdef
14. What is the output of this program?
import java.io.*;
class Chararrayinput {
public static void main(String[] args) {
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try {
while ((i = input1.read()) == (j = input2.read())) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
abishekvk@outlook.com
}
}
a) Abc
b) Abcd
c) Abcde
d) None of the mentioned
15. Which of these classes can return more than one character to be returned to input
stream?
a) BufferedReader
b) Bufferedwriter
c) PushbachReader
d) CharArrayReader
16. Which of these class contains the methods used to write in a file?
a) FileStream
b) FileInputStream
c) BUfferedOutputStream
d) FileBufferStream
17. Which of these exception is thrown in cases when the file specified for writing it not
found?
a) IOException
b) FileException
c) FileNotFoundException
d) FileInputException
18. Which of these methods are used to read in from file?
a) get()
b) read()
c) scan()
d) readFileInput()
19. Which of these values is returned by read() method is end of file (EOF) is encountered?
a) 0
b) 1
c) -1
d) Null
20. Which of these methods is used to write() into a file?
a) put()
b) putFile()
c) write()
d) writeFile()

More Related Content

PPTX
Templates in c++
Mayank Bhatt
 
PPTX
Inheritance In Java
Manish Sahu
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Function C++
Shahzad Afridi
 
PDF
Inheritance and interface
Shubham Sharma
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
PPTX
Inheritance in Object Oriented Programming
Ashita Agrawal
 
PPTX
classes and objects in C++
HalaiHansaika
 
Templates in c++
Mayank Bhatt
 
Inheritance In Java
Manish Sahu
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Function C++
Shahzad Afridi
 
Inheritance and interface
Shubham Sharma
 
Templates in c++
ThamizhselviKrishnam
 
Inheritance in Object Oriented Programming
Ashita Agrawal
 
classes and objects in C++
HalaiHansaika
 

What's hot (20)

PDF
Inheritance in Java.pdf
kumari36
 
PPT
Inheritance : Extending Classes
Nilesh Dalvi
 
PPT
Java static keyword
Lovely Professional University
 
PPTX
Inheritance in OOPS
Ronak Chhajed
 
PPTX
java interface and packages
VINOTH R
 
PDF
Java I/o streams
Hamid Ghorbani
 
PPTX
C# Access modifiers
Prem Kumar Badri
 
PPTX
Introduction to oop
colleges
 
PPTX
Inheritance in java
HarshitaAshwani
 
PPTX
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
PPTX
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
Super keyword in java
Hitesh Kumar
 
PPTX
Type casting in java
Farooq Baloch
 
PPTX
Friend function & friend class
Abhishek Wadhwa
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
this keyword in Java.pptx
ParvizMirzayev2
 
PPTX
Templates in C++
Tech_MX
 
PPTX
Class or Object
Rahul Bathri
 
PPTX
Packages,static,this keyword in java
Vishnu Suresh
 
Inheritance in Java.pdf
kumari36
 
Inheritance : Extending Classes
Nilesh Dalvi
 
Java static keyword
Lovely Professional University
 
Inheritance in OOPS
Ronak Chhajed
 
java interface and packages
VINOTH R
 
Java I/o streams
Hamid Ghorbani
 
C# Access modifiers
Prem Kumar Badri
 
Introduction to oop
colleges
 
Inheritance in java
HarshitaAshwani
 
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Inner classes in java
PhD Research Scholar
 
Super keyword in java
Hitesh Kumar
 
Type casting in java
Farooq Baloch
 
Friend function & friend class
Abhishek Wadhwa
 
This keyword in java
Hitesh Kumar
 
this keyword in Java.pptx
ParvizMirzayev2
 
Templates in C++
Tech_MX
 
Class or Object
Rahul Bathri
 
Packages,static,this keyword in java
Vishnu Suresh
 
Ad

Similar to Multiple choice questions for Java io,files and inheritance (20)

PDF
Java Programming.pdf
RavinderKSingla
 
PDF
200 mcq c++(Ankit dubey)
Ankit Dubey
 
DOCX
Multiple Choice Questions for Java interfaces and exception handling
Abishek Purushothaman
 
PDF
E5
lksoo
 
PPT
Java Inheritance
Kapish Joshi
 
PDF
Java ppt Gandhi Ravi ([email protected])
Gandhi Ravi
 
PPTX
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
PPTX
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
PPTX
Java Quiz
Dharmraj Sharma
 
PDF
Java MCQ Important Questions and Answers
SONU HEETSON
 
PDF
ITI COPA Java MCQ important Questions and Answers
SONU HEETSON
 
PDF
sample_midterm.pdf
EFRENlazarte2
 
DOC
MX Server is my friend
Gabriel Daty
 
DOC
MX Server is my friend
Gabriel Daty
 
DOC
MX Server is my friend
Gabriel Daty
 
DOC
MX Server is my friend
Gabriel Daty
 
PDF
AJP.pdf
Swapnil Kale
 
PDF
Core java
prabhatjon
 
PPTX
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
Knowledge Center Computer
 
DOC
Java questions1
yash4884
 
Java Programming.pdf
RavinderKSingla
 
200 mcq c++(Ankit dubey)
Ankit Dubey
 
Multiple Choice Questions for Java interfaces and exception handling
Abishek Purushothaman
 
E5
lksoo
 
Java Inheritance
Kapish Joshi
 
Java ppt Gandhi Ravi ([email protected])
Gandhi Ravi
 
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
Java Quiz
Dharmraj Sharma
 
Java MCQ Important Questions and Answers
SONU HEETSON
 
ITI COPA Java MCQ important Questions and Answers
SONU HEETSON
 
sample_midterm.pdf
EFRENlazarte2
 
MX Server is my friend
Gabriel Daty
 
MX Server is my friend
Gabriel Daty
 
MX Server is my friend
Gabriel Daty
 
MX Server is my friend
Gabriel Daty
 
AJP.pdf
Swapnil Kale
 
Core java
prabhatjon
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
Knowledge Center Computer
 
Java questions1
yash4884
 
Ad

More from Abishek Purushothaman (7)

PPTX
Aws solution architect
Abishek Purushothaman
 
PPTX
Machine learning
Abishek Purushothaman
 
PPTX
Introduction to R for beginners
Abishek Purushothaman
 
PPTX
Mini Project presentation for MCA
Abishek Purushothaman
 
PPTX
Python Programming Basics for begginners
Abishek Purushothaman
 
PPTX
Interfaces in java
Abishek Purushothaman
 
PPT
Exception handling
Abishek Purushothaman
 
Aws solution architect
Abishek Purushothaman
 
Machine learning
Abishek Purushothaman
 
Introduction to R for beginners
Abishek Purushothaman
 
Mini Project presentation for MCA
Abishek Purushothaman
 
Python Programming Basics for begginners
Abishek Purushothaman
 
Interfaces in java
Abishek Purushothaman
 
Exception handling
Abishek Purushothaman
 

Recently uploaded (20)

PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Software Development Methodologies in 2025
KodekX
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
This slide provides an overview Technology
mineshkharadi333
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Doc9.....................................
SofiaCollazos
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Software Development Methodologies in 2025
KodekX
 

Multiple choice questions for Java io,files and inheritance

  • 1. [email protected] 1. Which of these is correct way of inheriting class A by class B? a) class B + class A {} b) class B inherits class A {} c) class B extends A{} d) class B extends class A {} 2. Which of the following statements are incorrect? a) public members of class can be accessed by any code in the program. b) private members of class can only be accessed by other members of the class. c) private members of class can be inherited by a sub class, and become protected members in sub class. d) protected members of a class can be inherited by a sub class, and become private members of the sub class. 3. What is the output of this program? class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } a) 0 b) 1 c) 2 d) Compilation Error 4. What is the output of this program?
  • 2. [email protected] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } a) 2 2 b) 3 3 c) 2 3 d) 3 2 5. What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B();
  • 3. [email protected] obj.i=1; obj.j=2; obj.display(); } } a) 2 2 b) 3 3 c) Runtime Error d) Compilation Error 6. What is the output of this program? class A { public int i; public int j; A() { i = 1; j = 2; } } class B extends A { int a; B() { super(); } } class super_use { public static void main(String args[]) { B obj = new B(); System.out.println(obj.i + " " + obj.j) } } a) 1 2 b) 2 1 c) Runtime Error d) Compilation Error 7. What is the output of this program? class A {
  • 4. [email protected] public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } a) 1 2 b) 2 1 c) 1 3 d) 3 1 8. A class member declared protected becomes member of subclass of which type? a) public member b) private member c) protected member d) static member 9. Which of the following is true about inheritance in Java? 1) Private methodsare final. 2) Protectedmembersare accessiblewithinapackage and inheritedclassesoutside the package. 3) Protectedmethodsare final. 4) We cannot override privatemethods. a) 1,2 and 4 b) Only 1 and 2 c) 1,2 and 3 d) 2,3 and 4
  • 5. [email protected] 10. What will be the output of this program? class A { int b = 50; } class B extends A { int b = 20; } public class MainClass { public static void main(String[] args) { A a = new B(); System.out.println(a.b); } } a) Compiler error b) 20 c) 50 d) None of the above 11. What is the output of this program? import java.io.*; class filesinputoutput { public static void main(String args[]) { InputStream obj = new FileInputStream("inputoutput.java"); System.out.print(obj.available()); } } Note: inputoutput.java is stored in the disk. a) true b) false c) prints number of bytes in file d) prints number of characters in the file 12. Which of these class can be used to implement input stream that uses a character array as the source? a) BufferedReader b) FileReader c) CharArrayReader d) FileArrayReader 13. What is the output of this program? import java.io.*; class Chararrayinput {
  • 6. [email protected] public static void main(String[] args) { String obj = "abcdef"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0,length,c,0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 0, 3); int i; try { while ((i = input1.read()) != -1) { System.out.print((char)i); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } a) Abc b) Abcd c) Abcde d) Abcdef 14. What is the output of this program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i; int j; try { while ((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
  • 7. [email protected] } } a) Abc b) Abcd c) Abcde d) None of the mentioned 15. Which of these classes can return more than one character to be returned to input stream? a) BufferedReader b) Bufferedwriter c) PushbachReader d) CharArrayReader 16. Which of these class contains the methods used to write in a file? a) FileStream b) FileInputStream c) BUfferedOutputStream d) FileBufferStream 17. Which of these exception is thrown in cases when the file specified for writing it not found? a) IOException b) FileException c) FileNotFoundException d) FileInputException 18. Which of these methods are used to read in from file? a) get() b) read() c) scan() d) readFileInput() 19. Which of these values is returned by read() method is end of file (EOF) is encountered? a) 0 b) 1 c) -1 d) Null 20. Which of these methods is used to write() into a file? a) put() b) putFile() c) write() d) writeFile()