Skip to main content

Posts

Practice MCQs

  1. What will be the Output of the following code? class X{                  static int x = 1;                        static class Y {                              static int y = x++;                                static class Z                                                                       {                                                                                         static int z = ++y;                                                                        }                                               }                }   class MainClass{     public static void main(String[] rk)    {                             System.out.print(X.x);                                             System.out.print(X.Y.y);                             System.out.print(X.Y.Z.z);         } } A. 113 B. 123 C. 111 D. None of These Ans: A 2.  Which of the following statement is TRUE about t he following code? public class Outer  {    private i
Recent posts

OLA-UBER Problem

Create two interfaces OLA and UBER both having a method public static Cab getCab() which returns the Cab object where Cab is a nested class inside OLA and UBER. Cab must have attributes cab_number and driver_name. A user rides 5 times using cabs of OLA and UBER randomly which are stored in an array. Now implement a method which should display the name of the driver and the company name i.e. OLA/UBER when the valid cab_number is entered by the user. Display "Invalid CAB details" when the cab_number entered by the user is incorrect.

Mock Test - 1

1. Which of the following is a byte stream class? A. ObjectInputStream B. Writer C. PrintWriter D. Scanner Ans: A 2. Which exception is thrown by read() method in InputStream class? A. IOException B. InterruptedException C. FileNotFoundException D. None of These Ans: A 3. Which of the following class is subclass of FilterInputStream? A. InputStream B. ObjectOutputStream C. FileInputStream D. BufferedInputStream  Ans: D 4. Which of these class contains the print() and println() methods? A. System B. out C. PrintStream D. BUfferedOutputStream Ans: C 5. Which of these is a method to clear all the data present in output buffer without terminating the stream? A. clear() B. fflush() C. flush() D. close() Ans: C 6. Which of these classes defined in java.io and used for file-handling are abstract? (i) InputStream        (ii) PrintStream    (iii) Reader        (iv) FileInputStream A. Only i     B. i and ii    C. Only iii    D. i and iii Ans: D 7. What is the output of this program? class MyE

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?           4. Define Anonymous class. Why we use anonymous class in Java?   5. Differentiate between static nested class and inner class in java. 6. Write a program to define a class named Demo which contains a local class named MyLocal inside its constructor. Define a method sayHello (String XXX) to display Hello XXX (e.g Hello Ravi if name is Ravi). Define a class named TestLocal which reads the name from the user and then invoke the sayHello method of MyLocal class.   7. Complete the following program as per comments. abstract class A   { abstract vo

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                                                            [10 Marks]                                                                             OR (b) (i) Write a program to sum all the elements of an double type array containing 10 elements.                                                                                                                                                         [5 Marks]      (ii) Write a program in which define a method to convert an array of double values into array of int values.Invoke that method from the main() method for displaying the output.             [5 Marks] 2 (a) Create a c

Practice Set

1. Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years. VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id. 2. Write a program to define two interfaces UGC and AICTE both having a default method int getAdmission() to take the admission and an abstract method String payFee(). getAdmission() in UGC must ask the percentage in qualifying exam and if the percentage >= 60 then generate the registration number and return. getAdmission() is AICTE must ask the user to join the counseling after 5 days and display the date of counseling and return the counseling token numb
What will be the output?  1. class DemoString   {    public static void main(String... rk )              {           StringBuilder b = new StringBuilder (" abcdef ");           b.delete (4,6);           b.ensureCapacity (22);           System.out.print ( b.capacity ());             b.ensureCapacity (23);           System.out.print ( b.capacity ());     } } 2.      import java.time.*; import java.time.format.*; class DemoDateTime {    public static void main(String...rk)     {          DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy/mm/dd"); LocalDateTime ldt = LocalDateTime.of(2015, 10, 10 , 11, 22);     System.out.println(dtf.format(ldt));            } }