Professional Documents
Culture Documents
Polymorphism Is The Ability of Different Objects To Respond in A Unique Way To The
Polymorphism Is The Ability of Different Objects To Respond in A Unique Way To The
Polymorphism Is The Ability of Different Objects To Respond in A Unique Way To The
=we have defined the run method in the subclass as defined in the parent class but it
has some specific implementation. The name and parameter of the method are the
same, and there is IS-A relationship between the classes, so there is method
overriding.
=In Java, two or more methods may have the same name if they differ in parameters
(different number of parameters, different types of parameters, or both). ...
These methods are called overloaded methods and this feature is called method
overloading.
= Overriding vs Overloading :-
32. If a Generic Type Is Omitted When Instantiating an Object, Will the Code Still Compile
= As generics did not exist before Java 5, it is possible not to use them at all. ... The
point to remember is that while backward compatibility and type erasure make it
possible to omit generic types, it is bad practice
= There may be times when you'll want to restrict the kinds of types that are allowed to
be passed to a type parameter. ... This is what bounded type parameters are for. To
declare a bounded type parameter, list the type parameter's name, followed by the
extends keyword, followed by its upper bound.
40. Write a File-Copy program which copies the content of one file to another. Take both the
file names from the user
import java.io.*;
import java.util.*;
throws Exception
try {
int n;
// byte of data
out.write(n);
finally {
if (in != null) {
// close() function to close the
// stream
in.close();
// the stream
if (out != null) {
out.close();
System.out.println("File Copied");
System.out.println(
"Enter the source filename from where you have to read/copy :");
String a = sc.nextLine();
// source file
File x = new File(a);
System.out.println(
String b = sc.nextLine();
// destination file
// contents from x to y
copyContent(x, y);
}
41. How to read data from a file ,using FileReader class?
Code
1. package com.javatpoint;
2.
3. import java.io.FileReader;
4. public class FileReaderExample {
5. public static void main(String args[])throws Exception{
6. FileReader fr=new FileReader("D:\\testout.txt");
7. int i;
8. while((i=fr.read())!=-1)
9. System.out.print((char)i);
10. fr.close();
11. }
12. }
42. Give usage of BufferedWriter and BufferedReader classes in Java with example
43. Write a code to generate database for Criket player using file handling operations
=Link
https://bedeveloper.wordpress.com/core-java/1write-a-java-program-for-a-cricket-player-
the-program-should-accept-the-details-from-user-max-10-player-code-nameruns-innings-
played-and-number-of-times-not-out-the-program-should-contain-fo/
44. Give the applications where design patterns can be applied ?
=NO
=Link
https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
50. Represent and implement a Shape interface which implements Circle ,Square, rectangle
using Fatory pattern