0% found this document useful (0 votes)
42 views2 pages

New Text Document

This document contains questions related to Java programming concepts like inheritance, operators, data types, strings, loops, methods, classes, objects, constructors, functions, and more. It asks the reader to define terms, write code snippets, explain concepts, and analyze/summarize code. It also contains a multi-part question that involves defining a Laptop class with methods to calculate discounts on laptops based on price.

Uploaded by

alok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

New Text Document

This document contains questions related to Java programming concepts like inheritance, operators, data types, strings, loops, methods, classes, objects, constructors, functions, and more. It asks the reader to define terms, write code snippets, explain concepts, and analyze/summarize code. It also contains a multi-part question that involves defining a Laptop class with methods to calculate discounts on laptops based on price.

Uploaded by

alok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

(1) What is inheritance ?

[2]
(2) Name the operators listed below r [2]
(0 <
(it) + +
(iii) &&
(iv) ? :
(3) State the number of bytes occupied by char and int data types. [2]
(4) Write one difference between / and % operator. [2]
(5) String x[ ] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”}; [2]
Give the output of the following statements :
(i) System.out.prindn(x[1]);
(ii) System.out.println(x[3].length{ )); ,
(6)
(a) Name the following : [2]
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
(b) What are the two ways of invoking functions? [2]
(c) State the data type and value of res after the following is executed: [2]
char ch = ‘t’;
res=Character. toUpperCase(ch);
(d) Give the output of the following program segment and also mention the number of
times
the loop is executed: [2]
int a,b;
for (a=6, b=4; a< =24; a=a + 6)
{
if (a%b= =0)
break;
}
System, out .println(a);
(e) Write the output: [2]
charch= ‘F’;
int m= ch;
m=m+5;
System.out.println(m+ ” ” +ch);
Question 3.
(a) Write a Java expression for the following : [2]
ax5 + bx3 + c
(b) What is the value of xl if x=5 ? [2]
x1 = + +x – X+ + + –x
(c) Why is an object called an instance of a class ? [2]
(d) Convert following do-while loop into for loop. [2]
int i = 1;
int d = 5;
do {
d=d*2;
System.out.println(d);
i+ + ; } while (i< =5);
(e) Differentiate between constructor and function. [2]
(f) Write the output for the following : [2]
String s= “Today is Test”;
System.out.println(s.indexOf(‘T’));
System.out.println(s.substring(0, 7) + ” ” + “Holiday”);
(g) What are the values stored in variables r! and r2: [2]
(i) double r1=Math.abs(Math.min(-2.83,-5.83));
(ii) double r2=Math.sqrt(Math.floor(16.3));
(h) Give the output of the following code: [2]
String A = “26”, B=”100″;
String D =A+B+”200″;
int x = Integer.parselnt(A);
int y = Integer.parselnt(B);
int d = x+y;
System.out.println(“Result 1 = ”+D);
System.out.prinln(“Result 2 = “+d); ,
(i) Analyze the given program segment and answer the following questions : [2]
for(int i=3;i< =4;i+ +) {
for(int j=2;j<i;j+ +) {
System.out.print(” “); }
System.out.println(“WIN”); }
(i) How many times does the inner loop execute ?
(ii) Write the output of the program segment.
(f) What is the difference between the Scanner class functions nextQ and
nextLine()? [2]
Question 1.
(a) Name any two basic principles of Object-oriented Programming.
(b) Write a difference between unary and binary operator.
(c) Name the keyword which :
(i) indicates that a method has no return type.
(ii) makes the variable as a class variable.
(d) Write the memory capacity (storage size) of short and float data type in bytes.
(e) Identify and name the following tokens :
(i) public
(ii) ‘a’
(iii) ==
(iv) {}
(8)
i>What is meant by a constructor?
ii>Why do we need a constructor as a class member?
iii> Why is an object not passed to a constructor by value? Explain.
iv>State the difference between constructor and method.
Question 2
An electronics shop has announced a special discount on the purchase of Laptops as
given below:
Category Discount on Laptop
Up to ₹25,000 5.0%
₹25,001 - ₹50,000 7.5%
₹50,001 - ₹1,00,000 10.0%
More than ₹1,00,000 15.0%
Define a class Laptop described as follows:
Data members/instance variables:
name
price
dis
amt
Member Methods:
A parameterised constructor to initialize the data members
To accept the details (name of the customer and the price)
To compute the discount
To display the name, discount and amount to be paid after discount.
Write a main method to create an object of the class and call the member methods.
(9) Define a function. What is meant by function prototype?
(10) Differentiate between pure and impure functions.

You might also like