Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.What will display from the following program when it is compiled and executed?

ID: 3752867 • Letter: 1

Question

1.What will display from the following program when it is compiled and

executed? Hint: It does compile clean. No partial credit. Must be exactly

what displays.

import java.util.StringTokenizer

public class CountEm

{

public static void main(String args [])

{

String spock = "Live long and prosper"

StringTokenizer trekkie = new StringTokenizer(spock, "vp")

String trash = trekkie.nextToken()

System.out.println(trekkie.nextToken())

} // end main method

} // end class CountEm

the answer is e long and

explain why the answer is “ e long and” and NOT

Li

E long and

Ros

Per

2. What is the difference between instance method vs class method java? And give example

3. What is the difference between File object vs file name ?

Explanation / Answer

1)

Answer:

output:

e long and

explanation:

spock is "Live long and prosper"

affter calling stringtokenizer

trekkie contains four tokens= {"Li", "e long and ", "ros","er"}

String trash = trekkie.nextToken();

after the above statmente, the first token which Li is removed from trekkie and assigned to trash

now trekkie contains 3 tokens= {"e long and ", "ros","er"}

so here the first token is : "e long and "

so, that is printed

System.out.println(trekkie.nextToken());

because the first token is : "e long and "

after that

trekkie contains 2 tokens= {"ros","er"}

that's why

"e long and "

is printed

2)

instance method is method that is intitialized or brought to memory with in the object

means when the object is created for a class, then the methods in that object are called as instance method

class methods are the methods in the class declaration and definition which are not initialized

example:

class stack

{

int n;

void add(int m)//here add is class stacks method, which is not intialized

{

n=n+m;

}

}

//creating object for class stack

stack s = new stack();//object created

s.add(5);//now here it is instance method

3)

File object is object used to open a file

file name is used as agrument for the file object, inorder to open a file

//if you find this helpfull, pls give a thumbs up

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote