Skip to main content

Posts

Showing posts from 2018

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));            } } 

Practice Set 2

1. Write an application for Mobile Store where the user can view the available mobile phones in the store according to his/her preference. Store the mobile phone objects having attributes model number, OS, and Price. User should be allowed to filter the phones on the basis of those features. If user selects the model number, then ask to enter the model number and then display all the details of the phone with the given model number. If user selects OD then ask to choose the OS( Android/Windows/IOS) and display all the mobiles with that OS. If the user selects Price then ask to enter the minimum and maximum amount and display all the mobiles which can be bought with that amount. Now ask the user to select the mobile and display the details and bill. 2. Write an application for Cellular Company which provides different post paid plans for Calling/SMS. Ask the user to select the service provider and Display the menu to select the plan/pay bill. If user wants to selec

Compile-time Binding and Run-time Binding (Static & Dynamic Binding)

Consider the following program: class Parent {    public void demo(double d)     {         System.out.println("Parent "+d);     }    public void test(double d)     {         System.out.println("Parent Test "+d);     } } class Child extends Parent {    public void demo(int d)     {         System.out.println("Child "+d);     }    public void test(double d)     {         System.out.println("Overriding test in Child "+d);     } } class CompileTimeBinding {    public static void main(String...rk)     {         Parent p = new Child();         p.demo(5);   //Compile time Binding         p.test(5);   //Run-time Binding               } }

Brainstorming

What will be the output of the following Programs? A. class If_Demo {   public static void main(String...rk){    int i =10;    if(true)     {         i=20;     }    else        System.out.print(i);    System.out.println(++i);   } } B. class WhileDemo {   public static void main(String...rk){    int i =10;    while(false)     {         i=20;     }     System.out.println(++i);   } }

Practice Test Week-1

1. Write an application that calculates and displays the weekly salary of an employee.  In the main() method, prompt the user to enter the hourly_pay_rate, regular_working_hours, and overtime_hours.  Create a separate method to calculate overtime pay, which is regular hours times the pay rate plus overtime hours times 1.5 times the pay rate; return the result to the main() method to be displayed. 2. When gasoline is Rs 120 per barrel, then the consumer’s price at the pump is between Rs 3.60 and  Rs 4.20 per gallon.  Create a class named GasPrice such that its main() method holds an integer variable named price_per_barrel to which you will assign a value entered by a user at run time.  Create a method to which you pass price_per_barrel. The method displays the range of possible prices per gallon. For example, if gas is Rs150 per barrel, then the price at the pump should be between Rs 4.50 and  Rs 5.25. 3. Create a class named TestBankAccount whose main()