0% found this document useful (0 votes)
31 views52 pages

JAV

Jav

Uploaded by

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

JAV

Jav

Uploaded by

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

Home

23 Java Programming

Standalone assignment

CA-1

Submissions

Here are your latest answers:

Question 1

class strreplace{

public static void main(String args[D{

String sl="My name is Java"

String replacestr=sl replaceAll("\s",");

System.out.println(replacestr):

Find the error/output

Response: MynameisJava

Correct answer: MynameisJava


Score: 1 out of 1 Yes

Question12

class abe

public static void main(String args|)

System.outprintln(args|o|);

Find the output if the execution command is like this

java arg1 java 111 222 333

Response: Error

Correct answer: 111

Score: 0 out of 1 No

Question 3

class str3

public static void main(String args[D{


String si=Java programming

System.outprintin(sl.endsWith("g"):

System.out.println(sl.ends With("a"));

ystem.out.println(s .ends With(" "):

System.out.println(sl.ends With("ing"));

Find the output

Response: true

false

false

true

Correct answer: true

ole

Taise

Ialse

true

Score: I out of I Yes

Question 4

class example

public static void main(String args[D{


String sl="ABCD EFG HIJK":

System.out.println(s .substring(2,6));

System.out.println(s .substring(2);

Find the Output

Response: CD E CD EFG HIJK

Correct answer: CD E CD EFG HIJK

Score: 1 out of 1 Yes

Question 5

class abe

public static void main(String args|)

for(int i-=0;:i<args.length;i++)

System.outprintln(args[i):

Find the output if the execution command is like this

Java arg Java aaa bbb ccc ddd eee

Response: Error: cannot pass argument in command line


Correct answer: aaa

bbb

ddd

eee

Score: 0 out of I No

Question 6

import java.util.Scanner

class enpoyee

public static void main(stringll args

String name: o hold the employee s name

har gender: // To hold the employee's gender

Joubie s.alàry: 1o hold the empioyee s salary

Create a Scanner object to read input trom keyboard

n read employee's name from keyboard

ystem.out.print Enter name:

e" Console.nextline0:

/ ad

System.out.print(' Enter age:

7 rea .out.print('Enter gender:

gender console.next0.charAt(O):
W read salary

alaryconsoleevtDosled

W Display employee details

System.out.printin('Name:nameAge:" age Gender:gender"Salary:"salary):

Enter name: Prabhu Kumar

Enter gder Aale

Enter salary: 56/89

find the output based on these input

Response: Name: Prabhu Kumar

Age 34

Gender: Male

Salary: 56789

Correct answer:

Name: Prabhu Kumar

Age: 34 Gender: M

Salary: 56789.0

Score: 0 out of 1 No

Question 7
class strcompare

public static void main(String args| I){

String sl=" Zello";

String s2="hello";

System.out.println(s1.compareTo(s2);

Find the output

Response: 18

orrect answer: 18

Score: 1 out of 1 Yes

Question 8

class test

public static void main(String a[])

String a="HELLO";

System.out.println(a);

What is the error/output?


Response: HELLO

Correct answer: variable a is already defined in method main(String[)

Score: 0 out of 1 No

Question 9

class Test {

public static void main(Stringl| args)

String sl = "HELLO";

String s2 = "HELLO":

String s3 = new String("HELLO");

System.out.println(s l=S2);

System.out.println(sl =S3);

System.out.println(sI.equals(s2);

System.out.println(s l.equals(s5);

Find the output

Response: true

false

true

true
Correct answer: true

Ialse

rue

true

Score: 1 out of 1 Yes

Question 10

How many bytes are allocated for int data type in Java?

Response:4

Correct answer: 4

Score: I out of 1 Yes

Question 11

class ForCheck

public static void main(String a[1)

for(int i=1;i<=5;it+)

for(int j=-5;j>=lj-)
System.outprint(+ "++

Find the Eror/Output

Response:

1 5,1 4,1 3,1 2,1 12

5,2 4,2 3,2 2,2 1,3

5,3 4,3 3,3 2,3 14

5,444342,4 15

5,5 45 35 251,

correct answer:

1 5,1 4,1 3,1 21 12

5,2 4,2 3,2 2,2 1,3

5,3 4,3 33 2.3 14

5444 342415

55 4,5 3,525 1,

Score: 1 out of 1 Yes


Question 12

class ForCheck

public static void main(String al})

for(int i=1;i=5:it+);

for(int j= 1j=5jt+)}

System.outprint(+ +)

Findout the Error or Output

Response: Program Executes (No Error)

Correet answer: Cannot find symbol: i and j

Score: 0 out of I No

Question 13

class test

int a,bcd;

test(int x.int y, int z)


a=x;b=y:=L,

d=a

Class Pqr

public static void main(String al1)

test tl=new test(10,10,10)

test t2,13;

t3=t2=tl;

System.out.println(t3.d);

Find the Error/Output

Response: Eror: Can not display t3.d in main

Correct answer: 30

Score: 0 out of 1 No

Question 14

class Strtoint

public static void main(String args[ |)


String s="123";

int i=nteger.parseInt(s);

System.outprintin(S +526)

System.out.println(i+210);

Find the error/output of this program

Response: 123526

333

Correct answer: Compilation Error: due to String and integer addition

Score: 0 out of 1 No

Question 15

class test

public void main(String af[D

System.out.println("Hello");

What is the error/output?

Response: Error: Missing static keyword


Correct answer: Error: Missing static keyword

Score: 1 out of 1 Yes

Question 16

Why main is a static function?

Response: Compiler can call it without the creation of an object or before the creation of an
object of the class.

Correct answer: Compiler can call it without the creation of an object or before the creation of
an object of the class.

Score: I out of I Yes

Question 17

class Demo{

publie statice void main(String[] args)

int final = 10;

System.out println(final):

Response: error:final is a keyword and cannot be used as identifier

Correct answer: error:final is a keyword and cannot be used as identifier


Score: 1 out of 1 Yes

Question 18

class abe

public static void main(String args| )

System.out.println(args.length);

Find the output if the execution command is like this

java arg2.java aaa bbb ccc ddd

Response: Error

Correct answer: 4

Score: 0 out of 1 No

Question 19

class x

public static void main(String args[)


String name="ABCDEFG";

char ch=name.charAt(5);

System.out.println(ch);

Find the output

Response: F

orrect answer: F

Score: 1 out of I Yes

Question 20

class ForCheck

public static void main(String a[])

int s

for(int i=1j=5;i<=5ittj-)

s=S+(1+j);

System.out,println(s);

Findout the error/output of this program?

Response: For loop Syntax error


Correct answer: 30

Score: 0 out of I No

Question 21

class string9

public static void main(String args[D

String s1="ABCDEFGHIJ";

byte ar[]=slgetBytes0

System.outprintin(ar|[7);

Find output

Response: 72

Correct answer: 72

Score: I out of I Yes

Question 22

class one
public static void main(String argll)

System.out.printin( 'Hello from class: one'):

class two

public static void mainString argll)

System.out.printin( Hello from class: two'

class three

public static void main(String argl

one o new one0:

w w woo.

For the following java file, how many class file will create?

Find the output this program execution based on the

tollowing commanas

java on

the

Response: Hello from class: one

Hello from class: two

Correct answer: Hello from class: one

Hello from class: two


Score: 1 out of 1 Yes

Question 23

class test

int a,b.c:

test(int x.int y, int z)

a=x;b=y:cZ; a=atb+cC;

System.out.println(a):

test(int x, int y)

a=x; b

=10; a=at+b+C;

System.out.println(a);

test(int x)

a=x; b=10;

=10; a=atb+C;

System.out.println(a);
class

Pqr

public static void main(String a[])

test tl=new test(10,10,10):

test t2=new test(10,10);

test t3=new test(10);

Find the output?

Response: 30

S0

Correct answer: 30

S0

30

Score: 1 out of 1 Yes

Question 24

class ForCheck

public static void main(String allD

for(int i=1j=5;i=5ittj-)
System.outprintln(1+" +)

Findout the error/output of this program?

Response: For loop Syntax error

Correct answer: 15

33

51

Score: 0 out of I No

Question 25

class xyz{

public static void main(String args[)

String name="ABCDEFG":

System.out.println(name|2]);

Find the error/output

Response: Error :Aray required, but String found


Correct answer: Error :Array required, but String found

Score: 1 out of 1 Yes

Question 26

class xyz{

public static void main(String args[))

String name="ABCDEFG";

char|] ch=name.toCharArray0;

System.out println(ch[2]D:

Find the error/output

Response: C

orrect answer: CC

Score: 1 out of 1 Yes

Question 27

String name;
student(int r, String s)

rollno=r;

name=s;

class xyz

public static void main(String a[])

student firststudent=new student(111,"Nisha"):

student secondstudent=new student(222,"Asha");

student thirdstudent=secondstudent

student fourthstudent=new student(111, "Nisha");

if(thirdstudent.equals(secondstudent))System.out.printin("True

if(secondstudent.equals(firststudent))System.out.println("True2");

if(fourthstudent.equals(firststudent) )System.out.printin("True3");

if(fourthstudent-=firststudent)System.out.println("True4");

if(thirdstudent==secondstudent)System.out.println("True5");

ind the output

Response: Truel

Trues

True4

Trues

Correct answer: Truel


Trues

Score: 0 out of 1 No

Question 28

class string4

public static void main(String args[D

String sl=" Hello All "

System.outprintin(sl .trim)+"Welcome to JU");

From the above program, remove trim) method and find the output

Response: Hello AllWelcome to JU

Correct answer: Hello AllWelcome to JU

Score: 1 out of 1 Yes

Question 29

class Demo{

public static void main(Stringl| args) {


int a=10;

int b=att;

ystem.out.printin(a);

System.out.println(b)

Kesponse: 11

Correct answer: IT

10

Score: 1 out of 1 Yes

Question 30

class abe

public static void main(String args[)

int sum=0

for (int i=0;i<args.length:i++)

sum=sum+Integer.parselnt(args{i|);:

System.out.printn(sum);

Find the output if the execution command is like this

java arg3.java 10 20 30 40

Response: 10
Correct answer: 1000

Score: 0 out of 1 No

8/8/22, 11:36 PM Submissions Semesters CA-2-

Home

Semesters

Standalone assignment

CA-2

Submissions

Here are your latest answers:

Question 1

Which method is used for setting priority to threads?


Response: setPriority(0

Correct answer: setPriority)

Score: I out of 1 Yes

Question 2

class example

public statie void main(String argsD{

String sl="ABCD EFG HIUK";

System.out.println(sI.substring(2,6)

System.outprintin(sl .substring(2))

Find the Output

Response: CD E

CD EFG HIJK

Correct answer: CDE

CD EFG HIJK

Score: 1 out of I Yes

Question 3
For throwing user defined exception, which class is extending?

Response: Exception

Correct answer: Exception

Score: 1 out of 1 Yes

Question 4

Which is the class name from this code?

double tjava.lang.Math.sqrt(x);

Response: Math

Correct answer: Math

Score: 1 out of 1 Yes

Question 5

Why main is a static function?

Response: Compiler can call it without the creation of an object or before the creation of an
object of the class.
Correet answer: Compiler can call it without the creation of an object or before the creation of
an object of the class.

Score: 1 out of 1 Yes

Question 6

8/8/22, 11:36 PM Submissions Semesters CA-2-

Which keyword is used in class that using interface?

Response Implements

Correct answer: Implements

Score: 1 out of 1 Yes

Question 7

How to achieve 100% abstraction in java?

Response: interfaces

Correct answer: interfaces

Score: 1 out of 1 Yes


Question 8

class forcheck

public static void main(String a[])

for(int i=1;i=5;i++)

for(int j=lj<=ij+)

System.out.print(i);

System.out.println("")

Find Out the output

Response:1

4444

55555

Correct answer: I

4444

55555
Score: 1 out of 1 Yes

Question 9

Where to use super method?

Response: Sub class constructor

Correct answer: Sub class constructor

Score: 1 out of 1 Yes

Question 10

Which method is not used for blocking a thread?

Response: stop()

Correct answer: stopO

Score: 1 out of 1 Yes

Question 11
Which package is helpful in implementing GUI?

Response: java.awt

Correct answer: java.awt

Score: 1 out of 1 Yes

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 2/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

Question 12

class strtoint

public static void main(String args)

String s"123";

int i-Integer.parselnt(sS

System.out.println(s+526);

System.out.println(it+210);

Find the error/output of this program


Response: 123526

333

Correct answer: 123526

333

Score: 1 out of 1 Yes

Question 13

class strcompare{

public static void main(String args[)

String sl=""zello"

String s2=""hello";

System.out.println(sl.comparc'To(s2);

Find the output

Response: 18

Correct answer: 18

Score: 1 out of 1 Yes

Question 14
Which is representing current instance of a class ?

Response: this)

Correet answer: this(0

Score: I out of 1 Yes

Question 15

Which company released Latest version Java SE 17.0.1?

Response: Oracle Corporation

Correet answer: Oracle Corporation

Score: 1 out of 1 Yes

Question 16

"class test

public void main(String all)


System.out.println(""Hello"");

What is the error/output?"

Response: Error: Missing static keyword

Correct answer: Error: Missing static keyword

Score: I out of 1 Yes

Question 17

What will happen to currently running thread, If thread of a higher priority comes?

Response: Preempted

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 3/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

Correct answer: Preempted

Score: I out of 1 Yes

Question 18
Which method is called in java to reclaim the space for that object?

Response: Finalize()

Correct answer: Finalize()

Score: I out of I Yes

Question 19

The container for classes and other packages are called?

Response: Package

Correct answer: Package

Score: I out of I Yes

Question 20

"class abec

public static void main(String args])

System.out.printin(args.length);
Find the output if the execution command is like this

Java arg-Java aaa bbb ccc ddd"

Response:4

Correct answer: 4

Score: 1 out of 1 Yes

Question 21

Which exception is caused by referencing a null object?

Response: NullPointerËxception

Correet answer: NullPointerException

Score: 1 out of I Yes

Question 22

Which field is not visible anywhere except in its own class?

Response: private
Correct answer: private

Score: I out of I| Yes

Question 23

class xyz

public static void main(String args[])

String name-"ABCDEFG"

char[] ch=name.tocharArray O;

System.out.printin(chnl2])

Find the error/output

Response: C

Correet answer: C

Score: 1 out of 1 Yes

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 4/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

Question 24
class exp

public static void main(Stringl] args)

intiInteger.parselnt(""abc""

Ccatch(Exception ex)

System.out.println("" Catch Block")

catch(NumberFormatException ex)

System.out.printin(Number format error"");

Response: Compilation eror: exception NumberFormatException has already been caught

Correct answer: Compilation error: exception NumberFormatException has already been caught

Score: I out of 1 Yes

Question 25

Discuss Java language concept rclated to pointers?

Response: Usage of pointers can make it challenging. Pointer utilization can also cause
potential memory errors.

Correct answer: Usage of pointers can make it challenging. Pointer utilization can also cause
potential memory erTors.

Score: I out of I Yes

Question 26

In which state thread is ready and waiting for CPU?

Response: Runnable

Correct answer: Runnable

Score: I out of I Yes

Question 27

class forcheck

public static void main(String al])

int s

for(int i= 1j=5;i=5;ittj-)

s-st(i+j);

System.out.printn(s);

Find Out the error/output of this program?


Response: 30

Correct answer: 30

Score: 1 out of I Yes

Question 28

class A

final void display)

System.out.println("class A");

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 5/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

class B extends A

void display0

System.out.println("class B");

public static void main(Stringl|] args)


b new BO;

b.displayO0

What is the Output?

Response: Program Won't compile: cannot override display method which is final

Correet answer: Program Won't compile: cannot override display method which is final

Score: 1 out of 1 Yes

Question 29

Which interface is used to create a thread?

Response: Runnable

Correct answer: Runnable

Score: 1 out of 1 Yes

Question 30

The capability to control the access of multiple threads to any shared resource is called?
Response: Synchronization

Correct answer: Synchronization

Score: I out of I Yes

Question 31

Which method is used to invoke run method?

Response: start()

Correct answer: start)

Score: 1 out of 1 Yes

Question 32

class B

body of class B

here class B is?

Response: Default
Correct answer: Default

Score: I out of I Yes

Question 33

Which exception is related to bad array indexes?

Response: Array IndexOutOfBounds Exception

Correct answer: AraylndexOutOfBoundsException

Score: 1 out of 1 Yes

Question 34

class test

public static void main(String arg[|)

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 6/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

nt a-25;

int b=0;
ry

int c= a/b;

tinally

System.out.println("In finally");

Response: In finally

Exception in thread "main" java.lang.ArithmeticException: / by zero

at test.main

Correct answer: In finally

Exception in thread "main" java.lang.Arithmetic Exception: /by zero

at test.main

Score: 1 out of 1 Yes

Question 35

Which exception is caused by an attempt to access a non exísting file?

Response: FileNotFoundException

Correct answer: FileNotFoundException


Score: I out of I Yess

Question 36

class string9

public static void main(String args[){

String sl=""ABCDEFGHIJ";

byte ar[sl.getBytes():

System.out.println(ar[7]);

Find output

Response: 72

Correet answer: 72

Score: 1 out of 1 Yes

Question 37

Which class that implements an interface does not implement all the methods of the interface?

Response: Abstract Class


Correct answer: Abstract Class

Score: 1 out of 1 Yes

Question 38

OutOfMemoryError is belongs to which class?

Response: lt is a sub class of java.lang. Error

Correet answer: It is a sub class of java.lang. Error

Score: 1 out of 1 Yes

Question 39

Which inheritance is implemented only with interfaces?

Response: Multiple

Correet answer: Multiple

Score: 1 out of I Yes

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 7/9
8/8/22, 11:36 PM Submissions Semesters CA-2-

Question 40

class abe

public static void main(String args)

System.out.println(args[O]);

Find the output if the execution command is like this

Java arg1Java I1l 222 333

Response: 111

Correct answer: l

Score: 1 out of 1 Yes

Question 41

Class test

public static void main(String arg[D


nt a-25;

int b-0;

try

a/D,

What is the output?

Response: CompilerError: try without 'catch', 'finally'

Correct answer: CompilerError: try without'catch', 'finally'

Score: I out of I Ycs

Question 42

class A

AO { System.out.println("In Class A");}

class B extends A

BO{System.out.println("In Class B");

class C extends B
COSystem.out.println"ln Class C"):}

class testl

public static void main(String a[])

C objc=new CO:}

What is the output?

Response In Class A

Class B

n Class

Correct answer: In Class A

n lass B

In lass C

Score: 1 out of 1 Yes

Question 43

class a

public static void main(String args[)

int sum=0
for (int i=0;i<args.length;it+)

sum-sum+lnteger.parselnt(args[1]);

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 8/9

8/8/22, 11:36 PM Submissions Semesters CA-2-

System.out.println(sum);

Find the output if the execution command is like this

java arg5.java 10 20 30 40

Response: 100

Correct answer: 100

Score: 1 out of 1 Yes

Question 44

Which classes are used as super classes whose properties are inherited by classes?

Response: Interfaces

Correct answer: Interfaces

Score: 1 out of 1 Yes


Question 45

"class test

public static void main(String a[))

String a=""HELLO""

System.out.println(a)

What is the error/output?

Response: Variable a is alrcady defincd in method main(String[])

Correct answer: Variable a is already defined in method main(String[)

Score: 1 out of I Yes

https://learn.jainuniversity.ac.in/student_quiz_assignment/submissions/33639229 9/9

You might also like