Docsity

banking system project on java, Thesis of Java Programming, Study notes of Programming Languages

Toggle sidebar
bg1
. banking system project on java,
Thesis of Java Programming
List the number of different class types in Java; for instance, abstract class. - correct
answerYou can declare a class as abstract ,final, private ,protected, nest it in another
class and so on.
These are some of the comment type of classes
1. Wrapper Class:-
2. Mutable Class:-
3. Abstract Class:-
4. Final Class:-
5. Anonymous Class:-
6. Input-Output Class:-
7. String Class:-
8. System Class:-
9. Network Class
"string - correct answer"
11. What is the logical problem with this code?
class Instrument {
Instrument() {
System.out.println("Constructor") ;
}
}
class Piano extends Instrument {
Piano() {
this() ;
System.out.println("Constructor") ;
}
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download banking system project on java, Thesis of Java Programming and more Study notes Programming Languages in PDF only on Docsity!

. banking system project on java,

Thesis of Java Programming

List the number of different class types in Java; for instance, abstract class. - correct answerYou can declare a class as abstract ,final, private ,protected, nest it in another class and so on. These are some of the comment type of classes

  1. Wrapper Class:-
  2. Mutable Class:-
  3. Abstract Class:-
  4. Final Class:-
  5. Anonymous Class:-
  6. Input-Output Class:-
  7. String Class:-
  8. System Class:-
  9. Network Class "string - correct answer"
  10. What is the logical problem with this code? class Instrument { Instrument() { System.out.println("Constructor") ; } } class Piano extends Instrument { Piano() { this() ; System.out.println("Constructor") ; }

} - correct answerthis() is not the correct statement to call the constructor of base class in derived class. Correct statement is: super()

  1. What is the output of the following code if you instantiate an object of Piano? class Instrument { Instrument() { System.out.println("Constructor") ; } Instrument(String msg) { System.out.println(msg) ; } } class Piano extends Instrument { Piano() { super("Instrument") ; System.out.println("Playing") ; } } - correct answerInstrument playing
  2. Which method is overloaded in the following classes? class Instrument { Instrument() { System.out.println("Instrument") ; } void instrument(String msg) { System.out.println("Piano" + msg) ; } void method() { System.out.println("method_1") ; } } class Piano extends Instrument { void instrument() { //method is overridden System.out.println("Piano") ; } } - correct answerThere is no overloaded methods however there is overridden method which is instrument

Default = Only accessible within classes within the same package. Can a class could be a subclass as well as a superclass at the same time? - correct answerYes it can. This is an example of multilevel inheritance Can a Java class inherits more than one class directly? - correct answerNo it cannot Can a static methods access an instance function? Show your answer with working example. - correct answerclass Main { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(new Movie("Force Awakens", 8.3, 2015)); list.add(new Movie("Star Wars", 8.7, 1977)); list.add(new Movie("Empire Strikes Back", 8.8, 1980)); list.add(new Movie("Return of the Jedi", 8.4, 1983)); // among objects doing sorting Collections.sort(list); //sorting function System.out.println("Movies after sorting : "); for (Movie movie: list) { System.out.println(movie.getName() + " " + movie.getRating() + " " + movie.getYear()); //instance function cannot access a static method but a static method can access a instance function } } } Closely examine this code and see how an anonymous class is created and used. interface Instrument { public void method() ; } class Piano { // constructor Piano() { print( new Instrument() { public void method() { System.out.println("Piano") ; } } ) ;

// method void print(Instrument inst) { inst.method() ; } } - correct answerBelow code is using interface to create an anonymous class. In an anonymous class, we are able to declare and instantiate the class together. Constructor - correct answerOnly invoked once in the lifecycle of an object Convert the methods in the following class to static methods and make all the necessary correction as a result of the conversion. class Basketball { int home = 0 ; int visitor = 0 ; void setHome(int score) { home = score; } void setVistor(int score) { vistor = score ; } } - correct answerclass Basketball { static int home = 0 ; static int visitor = 0 ; static void setHome(int score) { home = score; } static void setVistor(int score) { visitor = score ; } } // instance variable cannot exist in static method // Correct the problem in the following code. interface Instrument { double goldenRatio = 1.618 ; } class Piano implements Instrument { goldenRatio = 1.61803399 ; - correct answerdouble goldenRatio = 1. An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.

double width, height, depth; Box(double w, double h, double d) { width = w; height = h; depth = d; } Box() { width = height = depth = 0; } Box(double len) { width = height = depth = len; } } Give an example of a statement where the two operators "?" and ":" are used in unison. - correct answermin = (3>2)?3: ternary operator java Give an example of downcasting. - correct answerAnimal animal = new Dog(); Dog castedDog = (Dog) animal; Give an example of upcasting. - correct answerDog dog = new Dog(); Animal anim = (Animal) dog; Give an example of your own class that cannot be overridden. - correct answerFinal How many interfaces can a class implements? - correct answerIn theory infinite Identify all the superclasses of Piano. class Instrument {} class Piano extends Instrument {} - correct answerInstrument Identify and explain what kind of casting the following snippet code is performing. class Instrument {} class Piano extends Instrument {}

Instrument inst = new Piano() ; //? Piano p = (Piano) inst ; //? - correct answerObject casting from large to small Upcasting object casting from small to large Downcasting Identify and explain what kind of casting the following snippet code is performing. class instrument {} class Piano extends instrumen {} Instrument inst=new Piano (); //? Piano p = (Piano) inst ; //? - correct answerInstrument inst=new Piano (); // this is upcasting Piano p = (Piano) inst ; //this is downcasting Identify and explain what kind of casting this statement is performing. double d = 3.0e8 ; float f = (float) d ; - correct answerprimitive type casting from higher to lower precision Identify the syntax errors class MyClass { } MYClass mc; - correct answerUncompilable source code - cannot find symbol: class MYClass If you were asked to convert the number 3.14159 to 3.0, how would you do it? - correct answerMath.floor(3.14159) implements - correct answerinterface import - correct answerjava.util.* ; JDK - correct answerJava Development Kit Object - correct answerall classes inherit it Object []array - correct answer{new String(), new Random(), new Scanner() } ; OOP - correct answerObject Oriented Programming System.in - correct answerStandard Input Device this - correct answerrefers to the current object

What Java keyword do you use to create a constructor link between a subclass and superclass' constructors? - correct answersuper What must be true for a subclass method to override the superclass method? - correct answerThe method that has the same name and number and type of perimeters and return type as the method that is overridden in the super class but it has more details. When your application starts, which method is invoked first by the JVM? - correct answerpublic static void main(String[] args) Which method is overridden by the subclass? class Instrument { Instrument() { System.out.println("Instrument") ; } void method() { System.out.println("method_1") ; } final void method(String msg) { System.out.println("method_1 " + msg) ; } void method(StringBuffer msg) { // method is overloaded System.out.println( "method_1 " + msg.toString() ) ; } } class Piano extends Instrument { void instrument() { System.out.println("Piano") ; } } - correct answerThere is no overridden method Surprisingly there is overloaded method which is called method Write a class that keeps track of the number of objects created from it. Hint: make the counter a static type. - correct answerclass sample { public static int counter=0; Sample () {

counter++; } } Write a program that sorts a given text order in an StringBuffer object. For instance, if the StringBuffer object value is "dcba", the outcome will be "abcd". - correct answerSystem.out.println(new StringBuffer("dcba").reverse().toString()); Write a program that sorts an array of Customer objects. The Customer class definition is provided below. You are strongly urged that you do solve this problem. class Customer { String name = "" ; String card = "" ; } - correct answer// A Java program to demonstrate use of Comparable import java.io.; import java.util.; // A class 'Movie' that implements Comparable class Movie implements Comparable //comparable and compareto method { private double rating; private String name; private int year; // Used to sort movies by year public int compareTo(Movie m) { return this.year - m.year; } // Constructor public Movie(String nm, double rt, int yr) { this.name = nm; this.rating = rt; this.year = yr; } // class building blue print // Getter methods for accessing private data public double getRating() { return rating; } public String getName() { return name; } public int getYear() { return year; }