Skip to main content

Posts

Practice Set: Inheritance, String, Array and ArrayList

1. WAP to create a class Person with attributes Name, Age and Mobile Number and a method to display the details of a person and an abstract method to assign the designation of the person as per the user input at run time. Create two subclasses of Person as Student and Employee and write the methods to accept the Organization name from the User at runtime and methods to display all the details of Student/Employee. Create the objects of both the subclasses using constructors to initialize the instance variables of the class and then display all the details of both.  2. WAP to create a class Vehicle having data members Mileage and fuel and methods to add the fuel. Create two sub classes of Vehicle i.e. Bike and Car each having data members Name, and Max_Speed and method to calculate the remaining fuel. From a class Race create the objects of both the subclasses using appropriate constructors to initialize the data members after taking the input from the user. Display the remaining ...

MCQ Test-1

MCQ Test Series Test-1 -------------------------------------------------------------------------------------- 1. Which of the following is FALSE about the Singleton Class? A. It provides the private constructor only. B. It provides a static factory method to return the instance of the class. C. It provides a public static reference of the same class type. D. None of These 2. What will be the output:   class Continue {      public static void main(String args[]){            for(int i=0; i<5; i++) {                         System.out.print(i + " ");                         if (i%2 == 0) continue;           ...

Determine the Output of the following Programs:

class Test {    Test(int a, double l)     {         System.out.println("First");     }    Test(int a, float l)     {         System.out.println("Second");     }    public static void main(String [] rk)     {         Test t = new Test(4, 5);     } } --------------------------------------------------------------------- class Test {    Test(int a, long l)     {         System.out.println("First");     }    Test(int a, float l)     {         System.out.println("Second");     }    public static void main(String [] rk)     {         Test t = new Test(4, 5);     } }

What will be the Output?

class Parent {    static void show() { System.out.println("static show in Parent"); }    void show1() { System.out.println("Parent show1"); } } class Child extends Parent {    static void show() { System.out.println("static show in Child"); }    void show1() { System.out.println("Child show1"); }    public static void main(String rk[]) { Parent p = new Child(); p.show(); p.show1(); } } Predict the output and draw a conclusion from that regarding the invocation of static and non-static methods.

Review Questions

Topic: Applet, AWT and Event Handling 1. What are Applets? How it is different from Normal java class? 2. What is the difference between Panel, Applet, Window and Frame? Can we add a Frame within a Panel? 3. Explain the Applet Life cycle. What is the importance of paint() and repaint(). 4. List various methods of Graphics class. Write code snippet to draw the following shapes in Applet: String, Rectangle, Oval, Circle, Rounded Corner Rectangle, Polygon and Polylines. 5. What do you mean by Event Handling? Explain Event Delegation Model. How will you register an event source with Listener? Write code snippet. 6. WAP to create a GUI having 4 text fields in four different sides of a frame and a button at the center. Contents of Text fields must be swapped (North<--> South and East<--> West) when the button is pressed 7. WAP to create an applet displaying a ball filled with blue color. Use event handling to move the ball with the mouse-pointer. 8. Wh...